I have a spotlight pointing at a car and casting a nice looking shadow on my ground.
The spotlight light is parented to the car so it follows it in the game engine. But when the car turns the orientation of the spotlight follows the car. I’d like the spotlight to follow the car but not change the rotation of the spotlight. Hope that makes sense.
Just select the light, then shift-select the car like a normal parenting, but instead of doing Ctrl-P asap, you enter edit mode with Tab and select a vertex, then Ctrl-P as usual…
Or you could use a ChildOf constraint, and just copy location, but not rotation. I just did this exact same thing in a little realtime scene I’m making. Works very well.
@ PadrePiox just tried the vertex parent method and it works great but because the car is self shadowing I sometimes get glitches/artefacts in the shadow cast on the car. I could avoid the glitches before because the spotlight was had less freedom to move.
@radialronnie how can I make the ‘Childof’ constraint work in the game engine? I can get it to work in a normal view port. But not in the game engine.
Um, as I know constraints doesn’t work in the Game Engine, you could use python if vertex parenting won’t do, but note that for the shadow glitches, it usually isn’t the light, but the model, check if the normals are ok and you placed vertices correctly, if there are still problems, then its normal the realtime shadows of Blender are not that precise, maibe the newcoming soft shadows will do the trick
Here is a Script I made, I’m using it to parent as well a Spot Light and a Sky, so them only follow my car and the rotation remains still unless you specify it, hope this helps you
#-------------------------------------#
# Copy Only Location #
# By #
# Luis Raúl Robles Ramos #
#-------------------------------------#
import GameLogic
cont = GameLogic.getCurrentController()
own = cont.owner
objlist = GameLogic.getCurrentScene().objects
#Replace 'OBCarro' for your desired Object
CarroPos = objlist['OBCarro'].worldPosition
#Here you set the height
CarroPos[2] += 2
own.localPosition = CarroPos
is a simple code but helps a lot for many purposes
Here’s a blend for you, you can see what could be the problem, I’ve added a few comments there of what i think could be happening. Hope this time works for you, if not, just tell me again :o
yeh the same thing happens to me! im not sure what im supposed to do…the lamp seems
to dissapear- and then re-appear somewhere else…the same thing happened with the ‘Child of Constraint’ i need help!!
The script is good, though actually vertex parenting does exactly the same thing, it copies only the location without rotation and scale, so using a script for a simple light following a car is kinda useless ( if you are not going to expand the script with more features )
But the choice is yours, if you want to use a python script just to do what vertex parenting already does then its ok…