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[1])
closest = object_distance[0][0]
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
you did:
X) determine target teleport to target. All in one step.
Btw. I do not see why you create a quaternion. You could copy the complete transformation (KX_GameObject.worldTransform) or the orientation matrix (KX_GameObject.worldOrientation)
BluePrintRandom, It kind of worked. But the idea is: I have a character, to perform some actions, the character has to adjust in location and rotation with the closest object with the property “dest”, to perform this action with precision. The “adjustment” script will be triggered by a button and a radar (-Y axis) at a certain distance. This script you sent me just worked very well, but the character goes to the other object with “dest” after reaching the first one, and even if I leave the first object, The character ignores it. So the thing is… it should just go to the closest, without ignoring it. And there’s other thing, how could you make the character only get to X and Y location, without using Z axis?