I looked at a bunch of similar questions, and I cannot seem to find one that particularly answers my question. I am coding a simple 3d game, and I am trying to allow the player
basic Newtonian/D'Alembert physics dictate:
derivate(position)=velocity
derivate(velocity)=acceleration
and also backwards:
integrate(acceleration)=velocity
integrate(velocity)=position
so for your engine you can use:
rectangle summation instead of integration (numerical solution of integral). Define time constant dt [seconds]
which is the interval between updates (timer or 1/fps). So the update code (must be periodically called every dt
:
vx+=ax*dt;
vy+=ay*dt;
vz+=az*dt;
x+=vx*dt;
y+=vy*dt;
z+=vz*dt;
where:
a{x,y,z} [m/s^2]
is actual acceleration (in your case direction vector scaled to a=Force/mass
)v{x,y,z} [m/s]
is actual velocityx,y,z [m]
is actual position
a,v
to zero and x,y,z
to init positionv=0; a=0;
a
v
vector by collision normal
and maybe multiply by some k<1.0
(0.95 for example) to account energy loss on impact
You can add gravity or any other force field by adding g
vector:
vx+=ax*dt+gx*dt;
vy+=ay*dt+gy*dt;
vz+=az*dt+gz*dt;
also You can add friction and anything else you need
PS. the same goes for angles just use angle/omega/epsilon/I
instead of x/a/v/m
to be clear by angles I
mean rotation (pitch,yaw,roll)
around mass center