copy location without parent bge

Hi, i’m trying to get a spotlamp to follow a vehicle around for shadows.

If i parent it to the vehicle it follows, but when the vehicle turns the shadows stay in the same place relative to the vehicle, because the rotation is also being copied.

So i need the spot to copy the location of a vehicle with an offset, but not it’s rotation.

the copy location constraint would be perfect, but it doesn’t work with the game engine :frowning:

Vertex parent. This copies the relative location and not the orientation.

Just select both the vehicle and the shadow. Make sure that the vehicle is selected last. Go into edit mode, select a vertex, Ctrl + P and vertex parent. That should work!

With a simple script :slight_smile:

import bge

cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
own = cont.owner

own.worldPosition = scene.objects[“name of empty here”].worldPosition

Put the script, into the lamp, with a always sensors, with trigerring enable, now, add a empty in the same location of the lamp, and parent the empty to the car.

Or a vertex parent, see last comment. Sorry english.

Here a blend, with the last script, but the script is in a cube, not in a lamp(for can see), sorry english.


Lamp follow the cube.blend (461 KB)

Use armatures. Make an armature, then (in pose mode) give the bone a “copy location” constraint. The BONE, note… It’s under a different tab than the normal constraints. Set the object in the constraint to be the car. Still in pose mode, select the lamp and parent it to the bone, as you would normally parent an object. Go out of pose mode, then in logic bricks, set up an always>and>Armature:runArmature on the armature. That should be fine, and will be more accurate than python (no frame delay).

Thanks, it does :slight_smile: