Tips for keeping a character from rotating while moving diagonally on a slope

When moving at an angle to the collider, the issue becomes apparent:

https://i.sstatic.net/k3fF1.gif

Although I am using OimoPhysics, there seems to be no specific tag for this. This problem is commonly encountered in all physics engines. The scenario involves a ball sliding down an inclined surface while rotating around an axis that points upwards in the direction of greatest friction. The rotational movement is restricted to the upward axis, freezing rotations around other axes.

I have raised this issue on the OimoPhysics GitHub page: https://github.com/saharan/OimoPhysics/issues/65

Another similar issue can be found on the Cannon ES GitHub page with source code implemented in Three.js: https://github.com/pmndrs/cannon-es/issues/183

  • Explore the issue further using PlayCode:

https://i.sstatic.net/wuN9C.gif

However, switching from OimoPhysics to Ammo.js resolved the problem entirely:

https://i.sstatic.net/2dUpr.gif

Ammo.js also handles bigger angles (up to 42 degrees) smoothly:

https://i.sstatic.net/yWbka.gif

Answer №1

I managed to find a solution for this issue. It requires setting the rotation factor to (0, 0, 0) when pressing W and S keys, and to (0, 1, 0) when pressing A and D keys.

For a practical example using OimoPhysics and Three.js, you can check out:

            if (input === "u") {
                /* ... */
                playerBody.setRotationFactor(new OIMO.Vec3(0, 0, 0));
            }

            if (input === "d") {
                /* ... */
                playerBody.setRotationFactor(new OIMO.Vec3(0, 0, 0));
            }

            if (input === "l") {
                /* ... */
                playerBody.setRotationFactor(new OIMO.Vec3(0, 1, 0));
            }

            if (input === "r") {
                /* ... */
                playerBody.setRotationFactor(new OIMO.Vec3(0, 1, 0));
            }

https://i.sstatic.net/iZoL9.gif

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Switching between all tabs simultaneously in an MDX page (React + Gatsby + MDX) using @reach/tabs

Creating a Tab component for a Gatsby site has proved to be a bit tricky. Imagine having a page with multiple tabs all labeled the same: Heading 1 First tab block Tab 1 | Tab 2 Content Tab 1 Second tab block Tab 1 | Tab 2 Content Tab 1 for the second bl ...

Retrieve the file name (as well as other properties) when clicking on an image in dropzone.js

Is there a way in dropzone.js to retrieve the file name of an uploaded image when it is clicked? Check out this resource for more information: ...

Vue 3 - Child Component Script Not Updating with Reactive Prop Changes

I am facing an issue where I am trying to pass a reactive data as a prop to a child component in Vue 3. The data updates correctly in the child component's template, but it does not reflect in the child component's script. In the parent component ...

Express.js does not display console.log messages while routing

Just starting to explore Express and its middleware functions. var express = require('express'); var app = express(); app.get('/', function(req, res) { res.send('id: ' + req.params.id + ' and name: ' + req.param ...

Compatibility issues arise with static properties in three.d.ts when using the most recent version of TypeScript

When compiling three.d.ts (which can be found at this link) using the TypeScript develop branch, an error occurs with the following message: Types of static property 'Utils' of class 'THREE.Shape' and class 'THREE.Path' are i ...

The Raycaster intersections in Threejs are not updated in real-time when objects are added to the scene, but

Currently, I am in the process of developing a Minecraft-inspired game using Three.js. At the moment, my setup involves adding cubes to a scene along with a Raycaster that identifies if the pointer is hovering over any of the cubes. It then creates an ind ...

In an attempt to successfully retrieve data from a formatted XML API, I am working on making a straightforward API call using JavaScript/TypeScript

I'm currently working on a project that involves calling an API in XML format, but I'm having trouble getting any data to show up. So far, I've attempted to use both JavaScript and TypeScript for making the HTTP request, as well as trying o ...

Mismatched data types for function arguments

const x: Example = { toY: (y: Maple) => { return y.p; } }; interface Example { toY: (y: Pine) => void; } interface Pine { c: string; } interface Maple extends Pine { p: boolean; } Despite the warning for interface names ...

Validation in ASP.Net to ensure the correct number of days between the arrival and departure dates

One of my project requirements involves checking the validation of the number of days entered between two date selectors (From & To Dates). The constraint is that the difference should not exceed 100 days. I'm considering using ASP.NET validators for ...

Unable to retrieve JSON data from MySQL due to receiving a null value

Currently, I have tried the code below but am facing issues with retrieving data from MySQL. Here is the output: <script type="text/javascript> var somethings= [null,null,null]; </script> While it does show three posts, I seem to be s ...

Sending a list via Ajax in Django

I recently executed an Ajax call successfully: $.ajax({ url:'/quespaper/intermediate_table', type:'GET', processData: false, data:{'url_link':url_link_copy,'updated ...

Fill up mongoose with data on 3 schemas

I have successfully populated 2 schema, but I am facing difficulty in populating the third schema. Here are the schemas: Member Schema var mongoose = require('mongoose'); var bcrypt = require('bcryptjs'); var Schema = mongoose.Schema ...

What is causing the unexpected behavior of deferred.resolve in the q manual?

I can't seem to grasp this concept and it might be a silly question. Let's analyze the code snippet below: function throwError() { throw Error("can't touch this."); } var def = q.defer(); def.promise.then( function() { co ...

Using Node JS as both an HTTP server and a TCP socket client simultaneously

Currently, I am developing a Node.js application to act as an HTTP server communicating with a TCP socket server. The code snippet for this setup is displayed below: var http = require('http'); var net = require('net'); var url = requi ...

The window.addEventListener function is failing to work properly on mobile devices

Hey there! I am facing an issue in my JS code. I wrote this code because I want the menu to close when a visitor clicks on another div (not the menu) if it is open. The code seems to be working fine in developer tools on Chrome or Firefox, but it's no ...

JQuery-generated list malfunctioning in DB environment

I have encountered an issue with a simple form that includes a dropdown list generated from a database. When a user selects an item from the list, it should be displayed on the screen. However, I am facing a problem where using jQuery to call the PHP funct ...

Exploring JS files for bugs using VS Code

Just starting out with learning javascript. Currently trying to troubleshoot this basic code: console.log("Hello World!\n"); // there's a breakpoint here let million = 1_000_000; console.log(million); However, upon hitting the play b ...

Utilizing JavaScript to iterate through objects retrieved via Ajax calls

Recently, I've been diving into the world of Javascript and delving deep into AJAX. Utilizing Vanilla JS along with simple AJAX, my current task involves fetching a user object from a URL based on the user's input ID. Despite attempting to use .d ...

Experiencing difficulty importing .pem files into Express

Referred to by this previous inquiry which went unanswered: I've stumbled upon something peculiar. Despite my efforts, I am still unable to import my certificate. Every time I attempt to run my Node/express application, it crashes with the same error ...

Transmitting a form using an AJAX request with a jQuery script

My main objective is to develop a form that can send an image to the server using Ajax via jQuery. I previously posted this question on Stack Overflow (Problem sending a form with a jquery file component by ajax), but unfortunately, it was closed and I st ...