# How can I simulate physics steps in advance?

Think of the trajectory of two objects that will collide in the future. I want to display this collision as a prediction, so that the player can do something to avoid the collision.

At my disposal is the linear velocity at t_0, but if I only add that to my current position I just get a straight line (obviously) but if I save it in an object with python, this value will be available at the next timestep t_1 and I can reconstruct the change of velocity from that.

If I assume this change to be constant I can get to some curve, which is better, but it's still nowhere near what the gameobject will actually do.

Is there a better way to do this?

• Well, simulating motion in general is a pretty broad problem. What kinds of forces act on your objects? For example, are your objects falling under the force of gravity? Are they rolling on a curved surface? Commented Apr 30, 2016 at 3:01

I think you can use four ray sensors, info can be found here from blender api. Depending on what you are doing, you may want use radar.

From that if some sensor collides with some obj you can get the distance obj1.getDistanceTo(obj2), world trajectory and speedobj2.localLinearVelocity in m/s.

Anyway, I come up with this, the trajectory. I hope its useful.

from bge import logic
from mathutils import Vector
import math

class vehicle:

def __init__(self, body):
self.cont = logic.getCurrentController().owner
self.body = body
self.front_ray = self.cont.sensors["front_ray"]
self.main = self.moving
pass

def moving(self):
velocity = Vector((0,40,0))
velocity.magnitude = 4
self.body.setLinearVelocity(velocity,1)
self.body.applyRotation((0,0,0.02),1)
if self.front_ray.hitObject:
pass
pass

rot_obj = obj.localOrientation.to_euler()
self_rot = self.body.localOrientation.to_euler()

if rot_obj.z < max_angle_limit and rot_obj.z > min_angle_limit:
print("ALARM : COLLISION DETECTION FROM :", self.front_ray)

pass

def main(cont):
own = cont.owner

if not "init" in own:
own['init'] = True
own['vehicle'] = vehicle(own)

own['vehicle'].main()