Interpolation of render with fixed physics update

In Fix Your Timestep, they briefly address the remainder time in relation to rendering. Saying that remainder can be used to generate an interpolated rendering.

We can use this remainder value to get a blending factor between the previous and current physics state simply by dividing by dt. This gives an alpha value in the range [0,1] which is used to perform a linear interpolation between the two physics states to get the current state to render.

http://web.archive.org/web/20190506030345/https://gafferongames.com/post/fix_your_timestep/

So let’s say your last two physics updates we’ll call A and B are from 00:10.033 and 00:10.066, and it is now 00:10.070 when we want to perform a render. We have a remainder of .004.

I take “interpolation between the two physics states” to mean we compare all the objects in update A and B and slide them back from B towards A by 88% (.033-.004)/.033). This would mean I’m actually rendering the physical state at 00:10.037, correct? So my physics updates A and B are really more like “previous” and “next” and my interpolation is between the previous and the next, correct?

How to interact with Physics world from a non-physics world in a 2D game (a.k.a. character controllers)

I’m using a Raycast based character controller for my 2D platformer but I like to interact with 2D Physic objects, like to stand on a dangling chandelier and stuff like that and have that Physic-controlled object affect my raycast based one.

What’s the best way to approach this?

Thanks.

How to realistically simulate car physics

I’m making a car simulation in Javascript and I am using this website to help me with the physics: http://www.asawicki.info/Mirror/Car%20Physics%20for%20Games/Car%20Physics%20for%20Games.html

The current progress of the simulation can be seen on my website: https://cloudynet.tk/projects/car-sim/code.html

The problem I have is with the car steering physics. I have managed to get the low-speed steering to work correctly but the high-speed steering (where lateral forces are introduced) is very hard to get right. I understand how slip angles influence the lateral force but in my simulation, it is not working very well. I’m wondering if the implementation of the lateral force is correct or is there something wrong with the code? Also, I don’t quite understand if the longitudinal force and the lateral force affects a single velocity vector or is separated into two “directional” vectors.

Here’s my current physics function (whole code can be seen on the website):

applyPhysics() {     // Get car direction vector      let direction = new Vector(1, 0);     direction = Vector.rotate(direction, this.carAngle);      // LONGITUDINAL FORCES      // Traction forces     let tractionForce = direction.copy(); // Traction force (engine power)     if (this.engineForce) {         tractionForce.mult(this.engineForce);     }     else if (this.brakingForce) {         tractionForce.mult(-this.brakingForce);     }      // Frictional forces      let dragForce = this.velocity.copy(); // Air resistance force     dragForce.mult(this.velocity.getMag())     dragForce.mult(-this.drag);      let rollingResistanceForce = this.velocity.copy(); // Rolling resistance force (friction with ground)     rollingResistanceForce.mult(-this.rrDrag);      let netLongitudinalForce = tractionForce.copy(); // Total longitudinal force     netLongitudinalForce.add(dragForce)     netLongitudinalForce.add(rollingResistanceForce);      // Calculate acceleration     this.acceleration = netLongitudinalForce.copy();     this.acceleration.div(this.mass);     if (this.acceleration.getMag() < 0.001)         this.acceleration = new Vector();      // Calculate velocity     let accelerationDelta = this.acceleration.copy();     accelerationDelta.mult(dt);     this.velocity.add(accelerationDelta);      this.velDir = this.velocity.getDir();     this.sideslipAngle = this.carAngle - this.velDir; // Calculate side slip angle      if (this.speed > 20) { // High speed-turning         // LATERAL FORCES          let peakSlipAngle = 5;          // Calculate slip angle for back wheel         var c = this.wheels.baseline/2;         var omegaC = this.angularVelocity*c;         var longV = Math.cos(this.carAngle) * this.velocity.getMag();         var latV = Math.sin(this.carAngle) * this.velocity.getMag();         this.wheels.back.slipAngle = Math.atan(((latV - omegaC)/Math.abs(longV)) || 0);         var backSlipDeg = deg(this.wheels.back.slipAngle)          this.wheels.back.lateralForce = 5000*Math.sign(this.wheels.back.slipAngle);         if (backSlipDeg < peakSlipAngle && backSlipDeg > -peakSlipAngle) {             this.wheels.back.lateralForce = 5000*backSlipDeg/peakSlipAngle;         } else {             this.wheels.back.lateralForce = 5000*(1-((Math.abs(backSlipDeg)-peakSlipAngle)/500))*Math.sign(this.wheels.back.slipAngle);         }          // Calculate slip angle for front wheel         var b = this.wheels.baseline/2;         var omegaB = this.angularVelocity*b;         var longV = Math.cos(this.wheels.front.slipAngle) * this.velocity.getMag();         var latV = Math.sin(this.wheels.front.slipAngle) * this.velocity.getMag();         this.wheels.front.slipAngle = Math.atan((((latV - omegaB)/Math.abs(longV)) || 0)-this.steeringAngle*Math.sign(longV));         var frontSlipDeg = deg(this.wheels.front.slipAngle);          this.wheels.front.lateralForce = 5000*Math.sign(this.wheels.front.slipAngle);         if (frontSlipDeg < peakSlipAngle && frontSlipDeg > -peakSlipAngle) {             this.wheels.front.lateralForce = 5000*frontSlipDeg/peakSlipAngle;         } else {             this.wheels.front.lateralForce = 5000*(1-((Math.abs(frontSlipDeg)-peakSlipAngle)/500))*Math.sign(this.wheels.front.slipAngle);         }          // Calculate cornering force         this.corneringForce = this.wheels.back.lateralForce + Math.cos(this.steeringAngle) * this.wheels.front.lateralForce;          // Calculate centripetal force         this.centripetalForce = this.mass * (this.velocity.getMag() ** 2) / this.wheels.baseline/Math.sin(this.steeringAngle);          var lateralDirection = new Vector(0, -1);         lateralDirection = Vector.rotate(lateralDirection, this.carAngle);          let lateralForce = lateralDirection.copy();         lateralForce.mult(this.corneringForce);          this.latAcceleration = lateralForce.copy();         this.latAcceleration.div(this.mass);         if (this.latAcceleration.getMag() < 0.001)             this.latAcceleration = new Vector();          let latAccelerationDelta = this.latAcceleration.copy();         latAccelerationDelta.mult(dt);         this.latVelocity.add(latAccelerationDelta);          // Calculate position         let latVelocityDelta = this.latVelocity.copy();         latVelocityDelta.mult(dt);         this.pos.add(latVelocityDelta);     } else {         this.velocity = Vector.rotate(this.velocity, this.carAngle - this.velDir); // Correct velocity based on car orientation     }      // Calculate position     let velocityDelta = this.velocity.copy();     velocityDelta.mult(dt);     this.pos.add(velocityDelta);      // Calculate speed     this.speed = this.velocity.getMag(); } 

How to realistically simulate car physics

I’m making a car simulation in Javascript and I am using this website to help me with the physics: http://www.asawicki.info/Mirror/Car%20Physics%20for%20Games/Car%20Physics%20for%20Games.html

The current progress of the simulation can be seen on my website: https://cloudynet.tk/projects/car-sim/code.html

The problem I have is with the car steering physics. I have managed to get the low-speed steering to work correctly but the high-speed steering (where lateral forces are introduced) is very hard to get right. I understand how slip angles influence the lateral force but in my simulation, it is not working very well. I’m wondering if the implementation of the lateral force is correct or is there something wrong with the code? Also, I don’t quite understand if the longitudinal force and the lateral force affects a single velocity vector or is separated into two “directional” vectors.

Here’s my current physics function (whole code can be seen on the website):

applyPhysics() {     // Get car direction vector      let direction = new Vector(1, 0);     direction = Vector.rotate(direction, this.carAngle);      // LONGITUDINAL FORCES      // Traction forces     let tractionForce = direction.copy(); // Traction force (engine power)     if (this.engineForce) {         tractionForce.mult(this.engineForce);     }     else if (this.brakingForce) {         tractionForce.mult(-this.brakingForce);     }      // Frictional forces      let dragForce = this.velocity.copy(); // Air resistance force     dragForce.mult(this.velocity.getMag())     dragForce.mult(-this.drag);      let rollingResistanceForce = this.velocity.copy(); // Rolling resistance force (friction with ground)     rollingResistanceForce.mult(-this.rrDrag);      let netLongitudinalForce = tractionForce.copy(); // Total longitudinal force     netLongitudinalForce.add(dragForce)     netLongitudinalForce.add(rollingResistanceForce);      // Calculate acceleration     this.acceleration = netLongitudinalForce.copy();     this.acceleration.div(this.mass);     if (this.acceleration.getMag() < 0.001)         this.acceleration = new Vector();      // Calculate velocity     let accelerationDelta = this.acceleration.copy();     accelerationDelta.mult(dt);     this.velocity.add(accelerationDelta);      this.velDir = this.velocity.getDir();     this.sideslipAngle = this.carAngle - this.velDir; // Calculate side slip angle      if (this.speed > 20) { // High speed-turning         // LATERAL FORCES          let peakSlipAngle = 5;          // Calculate slip angle for back wheel         var c = this.wheels.baseline/2;         var omegaC = this.angularVelocity*c;         var longV = Math.cos(this.carAngle) * this.velocity.getMag();         var latV = Math.sin(this.carAngle) * this.velocity.getMag();         this.wheels.back.slipAngle = Math.atan(((latV - omegaC)/Math.abs(longV)) || 0);         var backSlipDeg = deg(this.wheels.back.slipAngle)          this.wheels.back.lateralForce = 5000*Math.sign(this.wheels.back.slipAngle);         if (backSlipDeg < peakSlipAngle && backSlipDeg > -peakSlipAngle) {             this.wheels.back.lateralForce = 5000*backSlipDeg/peakSlipAngle;         } else {             this.wheels.back.lateralForce = 5000*(1-((Math.abs(backSlipDeg)-peakSlipAngle)/500))*Math.sign(this.wheels.back.slipAngle);         }          // Calculate slip angle for front wheel         var b = this.wheels.baseline/2;         var omegaB = this.angularVelocity*b;         var longV = Math.cos(this.wheels.front.slipAngle) * this.velocity.getMag();         var latV = Math.sin(this.wheels.front.slipAngle) * this.velocity.getMag();         this.wheels.front.slipAngle = Math.atan((((latV - omegaB)/Math.abs(longV)) || 0)-this.steeringAngle*Math.sign(longV));         var frontSlipDeg = deg(this.wheels.front.slipAngle);          this.wheels.front.lateralForce = 5000*Math.sign(this.wheels.front.slipAngle);         if (frontSlipDeg < peakSlipAngle && frontSlipDeg > -peakSlipAngle) {             this.wheels.front.lateralForce = 5000*frontSlipDeg/peakSlipAngle;         } else {             this.wheels.front.lateralForce = 5000*(1-((Math.abs(frontSlipDeg)-peakSlipAngle)/500))*Math.sign(this.wheels.front.slipAngle);         }          // Calculate cornering force         this.corneringForce = this.wheels.back.lateralForce + Math.cos(this.steeringAngle) * this.wheels.front.lateralForce;          // Calculate centripetal force         this.centripetalForce = this.mass * (this.velocity.getMag() ** 2) / this.wheels.baseline/Math.sin(this.steeringAngle);          var lateralDirection = new Vector(0, -1);         lateralDirection = Vector.rotate(lateralDirection, this.carAngle);          let lateralForce = lateralDirection.copy();         lateralForce.mult(this.corneringForce);          this.latAcceleration = lateralForce.copy();         this.latAcceleration.div(this.mass);         if (this.latAcceleration.getMag() < 0.001)             this.latAcceleration = new Vector();          let latAccelerationDelta = this.latAcceleration.copy();         latAccelerationDelta.mult(dt);         this.latVelocity.add(latAccelerationDelta);          // Calculate position         let latVelocityDelta = this.latVelocity.copy();         latVelocityDelta.mult(dt);         this.pos.add(latVelocityDelta);     } else {         this.velocity = Vector.rotate(this.velocity, this.carAngle - this.velDir); // Correct velocity based on car orientation     }      // Calculate position     let velocityDelta = this.velocity.copy();     velocityDelta.mult(dt);     this.pos.add(velocityDelta);      // Calculate speed     this.speed = this.velocity.getMag(); } 

How to realistically simulate car physics

I’m making a car simulation in Javascript and I am using this website to help me with the physics: http://www.asawicki.info/Mirror/Car%20Physics%20for%20Games/Car%20Physics%20for%20Games.html

The current progress of the simulation can be seen on my website: https://cloudynet.tk/projects/car-sim/code.html

The problem I have is with the car steering physics. I have managed to get the low-speed steering to work correctly but the high-speed steering (where lateral forces are introduced) is very hard to get right. I understand how slip angles influence the lateral force but in my simulation, it is not working very well. I’m wondering if the implementation of the lateral force is correct or is there something wrong with the code? Also, I don’t quite understand if the longitudinal force and the lateral force affects a single velocity vector or is separated into two “directional” vectors.

Here’s my current physics function (whole code can be seen on the website):

applyPhysics() {     // Get car direction vector      let direction = new Vector(1, 0);     direction = Vector.rotate(direction, this.carAngle);      // LONGITUDINAL FORCES      // Traction forces     let tractionForce = direction.copy(); // Traction force (engine power)     if (this.engineForce) {         tractionForce.mult(this.engineForce);     }     else if (this.brakingForce) {         tractionForce.mult(-this.brakingForce);     }      // Frictional forces      let dragForce = this.velocity.copy(); // Air resistance force     dragForce.mult(this.velocity.getMag())     dragForce.mult(-this.drag);      let rollingResistanceForce = this.velocity.copy(); // Rolling resistance force (friction with ground)     rollingResistanceForce.mult(-this.rrDrag);      let netLongitudinalForce = tractionForce.copy(); // Total longitudinal force     netLongitudinalForce.add(dragForce)     netLongitudinalForce.add(rollingResistanceForce);      // Calculate acceleration     this.acceleration = netLongitudinalForce.copy();     this.acceleration.div(this.mass);     if (this.acceleration.getMag() < 0.001)         this.acceleration = new Vector();      // Calculate velocity     let accelerationDelta = this.acceleration.copy();     accelerationDelta.mult(dt);     this.velocity.add(accelerationDelta);      this.velDir = this.velocity.getDir();     this.sideslipAngle = this.carAngle - this.velDir; // Calculate side slip angle      if (this.speed > 20) { // High speed-turning         // LATERAL FORCES          let peakSlipAngle = 5;          // Calculate slip angle for back wheel         var c = this.wheels.baseline/2;         var omegaC = this.angularVelocity*c;         var longV = Math.cos(this.carAngle) * this.velocity.getMag();         var latV = Math.sin(this.carAngle) * this.velocity.getMag();         this.wheels.back.slipAngle = Math.atan(((latV - omegaC)/Math.abs(longV)) || 0);         var backSlipDeg = deg(this.wheels.back.slipAngle)          this.wheels.back.lateralForce = 5000*Math.sign(this.wheels.back.slipAngle);         if (backSlipDeg < peakSlipAngle && backSlipDeg > -peakSlipAngle) {             this.wheels.back.lateralForce = 5000*backSlipDeg/peakSlipAngle;         } else {             this.wheels.back.lateralForce = 5000*(1-((Math.abs(backSlipDeg)-peakSlipAngle)/500))*Math.sign(this.wheels.back.slipAngle);         }          // Calculate slip angle for front wheel         var b = this.wheels.baseline/2;         var omegaB = this.angularVelocity*b;         var longV = Math.cos(this.wheels.front.slipAngle) * this.velocity.getMag();         var latV = Math.sin(this.wheels.front.slipAngle) * this.velocity.getMag();         this.wheels.front.slipAngle = Math.atan((((latV - omegaB)/Math.abs(longV)) || 0)-this.steeringAngle*Math.sign(longV));         var frontSlipDeg = deg(this.wheels.front.slipAngle);          this.wheels.front.lateralForce = 5000*Math.sign(this.wheels.front.slipAngle);         if (frontSlipDeg < peakSlipAngle && frontSlipDeg > -peakSlipAngle) {             this.wheels.front.lateralForce = 5000*frontSlipDeg/peakSlipAngle;         } else {             this.wheels.front.lateralForce = 5000*(1-((Math.abs(frontSlipDeg)-peakSlipAngle)/500))*Math.sign(this.wheels.front.slipAngle);         }          // Calculate cornering force         this.corneringForce = this.wheels.back.lateralForce + Math.cos(this.steeringAngle) * this.wheels.front.lateralForce;          // Calculate centripetal force         this.centripetalForce = this.mass * (this.velocity.getMag() ** 2) / this.wheels.baseline/Math.sin(this.steeringAngle);          var lateralDirection = new Vector(0, -1);         lateralDirection = Vector.rotate(lateralDirection, this.carAngle);          let lateralForce = lateralDirection.copy();         lateralForce.mult(this.corneringForce);          this.latAcceleration = lateralForce.copy();         this.latAcceleration.div(this.mass);         if (this.latAcceleration.getMag() < 0.001)             this.latAcceleration = new Vector();          let latAccelerationDelta = this.latAcceleration.copy();         latAccelerationDelta.mult(dt);         this.latVelocity.add(latAccelerationDelta);          // Calculate position         let latVelocityDelta = this.latVelocity.copy();         latVelocityDelta.mult(dt);         this.pos.add(latVelocityDelta);     } else {         this.velocity = Vector.rotate(this.velocity, this.carAngle - this.velDir); // Correct velocity based on car orientation     }      // Calculate position     let velocityDelta = this.velocity.copy();     velocityDelta.mult(dt);     this.pos.add(velocityDelta);      // Calculate speed     this.speed = this.velocity.getMag(); } 

CMake error while installing Bullet Physics (PYTHON_LIBRARY set to NOTFOUND)

Hello everyone I’m trying to install Bullet Physics in my Ubuntu 18.04 LTS.

I managed to install cmake successfully, but as soon as I try to run

./build_cmake_pybullet_double.sh 

it shows me the error

CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: PYTHON_LIBRARY (ADVANCED) 

I already installed python3-pip and other libraries, but why is this error happening?

(In usr/lib there are the following folders python2.7, python3, python3.6, python3.7)

Thanks in advance!

Does D&D physics enable a perpetual motion machine?

For various reasons perpetual motion machines are impossible in real life. They violate the laws of thermodynamics and cannot be created. It has been established, however, that D&D is not a physics simulator and the normal rules of physics do not apply.

Inspired by Shalvenay and MikeQ in chat. I was wondering, can a perpetual motion machine be made in D&D?


Imagine the following scenario:

Timmy the Tinkerer is going to a tinkering competition. The premise is simple; build the most magical device without using magic. The rules are as follows:

  • Magic cannot be used to create the item, and the item itself must not be magical.
  • It must be permanent, any item that relies on a once/day ability to sustain it will not count.
  • It must obey the physics of the material plane. No planar trickery is allowed.

Timmy decides he would love to make a perpetual motion machine.

Given these rules and using any officially available content; is it possible for Timmy to do this? For bonus points, how can he do it?

Technology stack for physics software

I have a project idea for a physics formula-simulation software with a possibility to extend it with custom plugins. I’m currently thinking about the tech-stack to use.

Thinking of the users and their background I’d say it’d would be most useful for people in academia and in my experience most of them know Python pretty well, which would give them the opportunity to write plugins in Python.

For the simulation part, I’m currently thinking 2d and 3d simulatins of various physics models, C++ could be used since it has various existing libraries in that field.

So my current outline is to use Python for the core, user interface, plugin interface. And to use C++ for the simulation part and use an interface library such as pybind11 or similar for the connection.

Does anyone have any experience with this type of software and has some input regarding the options of the tech-stack to use?