What I want here is to make an object move to the location and rotation of another object.
The target has to be the closest object with the property “dest”. The problem is… In my script, The object kind of teleports to the other location. I want it to move smoothly. Here’s the script:
import bge scene = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() own = cont.owner Near = cont.sensors['bang'] # objects with property objects_with_prop = [o for o in scene.objects if "dest" in o] target = objects_with_prop # closet dist = lambda o: (o.worldPosition - own.worldPosition).magnitude object_distance = [(o, dist(o)) for o in objects_with_prop] object_distance.sort(key=lambda t: t) closest = object_distance target = closest # copy rotation eu_own = own.worldOrientation.to_quaternion() eu_target = target.worldOrientation.to_quaternion() eu_own.z = eu_target.z eu_own.w = eu_target.w own.worldOrientation = eu_own own.worldPosition.x = target.worldPosition.x own.worldPosition.y = target.worldPosition.y