[SOLVED]Camera Collision Troubles (rayCast and empties used)

My camera went through any geometry so I thought I’d come up with a solution, been getting used to python recently and I thought I could do this :smiley: Comes to show my hands aren’t as mighty as I thought. Here is the script:


cameraE = scene.objects["cameraEmpty"]
camera = scene.objects["Camera"]
playerE = scene.objects["camera_empty"]
cameraOrigPos = scene.objects["cameraOriginal"] #empty at the original position of camera
	
obj, hitPoint, normal = playerE.rayCast(cameraE, playerE, 0, "", 0, 0, 0)
#ray from player empty to camera empty.
init = 0
if obj != None:
    camera.position = hitPoint
    init = 1
if obj == None:
    if init == 1:
        camera.position = cameraOrigPos.position
        init = 0

Console gives no errors but I feel something in there is fundamentally wrong.

When the ray collides with something the camera goes mental and snaps to a point close to the player rather then one that the collision was with.
I originally thought that the ray may be colliding with my character controller capsules mesh, but that is not the case,
any ideas?

##Shameless Bump
C’mon lads, any help is good help right now :slight_smile:

Would you mind posting your .blend to save us the trouble of re-creating your scene?
Thanks!

Yeah, I’m guessing there’s some parenting issues going on, since just casting a ray from the Player to the Camera empty isn’t enough to cause such problems - it must have to do with the parenting, as well.

Aye, parenting sounds like it would be the issue! I just can’t spot it! Here’s my blend


[http://www.pasteall.org/blend/6572](http://www.pasteall.org/blend/6572)

Thanks guys

Light Bulb!!! Lads, you set me on the right track! It works now :smiley:
I changed the rayCast code a bit:


obj, hitPoint, normal = playerE.rayCast(cameraE, playerE, 0, "", 0, 0, 0)
#ray from player empty to camera empty.
if obj != None:
    camera.position = hitPoint
if obj == None:
    camera.position = cameraOrigPos.position
    init = 0

And I completely unparented the camera, gave it a Track To actuator and it works like a cog wheel in a grindhouse!

Thank you all! I’m well cool :smiley: