Shadow spotlight following cars

Hi there

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.

Any ideas how to do this? cheers

You have to use vertex parenting:

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…

Nice car model you have here by the way :slight_smile:

Hope this helps you,
Cya =)

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.

thanks in advance

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 :slight_smile:

Cya =)

Yes I think I might have to write a small Python script.

I think the model is ok but it’s just a limitation of the shadow system.

has the soft shadow patch being officially accepted?

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 :slight_smile:

#         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

Very nice car model! you making a game? :smiley:

@Pikol cool. thanks for the script. I’ll plug it into to my scene and report back. thank you

@Jaysusfreak I’m making a sandbox environment not a game

ohh cool can’t wait ti see it :slight_smile:

Sorry, forgot to say the script must be atached to the spot lamp:o

s’cuze me???

I have no suggestion… but, I really need to say this - “That jeep is AWESOME!”

No luck. The scripts runs without any errors. The spotlight doesn’t move at all.

any ideas where I might be going wrong?

thank you

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


CopyLoc.blend (134 KB)

Wow Xbox-status jeep right there!

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!!

its Ok!! the wertex parent thing really does work!

Sucess! :slight_smile: Thank you very much for the example scene

However I still get the self shadow artefacts on the car though. If I only cast the shadow on the floor (and not the car as well) it’s good.

thank you again!

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… :stuck_out_tongue:

Cya =)

EDIT: Here’s the same .blend with vertex parent…


VertexParent.blend (130 KB)