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?

  • $\begingroup$ 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? $\endgroup$ Apr 30 '16 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

    def moving(self):
        velocity = Vector((0,40,0))
        velocity.magnitude = 4
        if self.front_ray.hitObject:

    def check_thread(self, obj):
        rot_obj = obj.localOrientation.to_euler()
        self_rot = self.body.localOrientation.to_euler()
        max_angle_limit = math.radians(-160)
        min_angle_limit = math.radians(-200)

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


def main(cont):
    own = cont.owner

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



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.