How to avoid camera going through rigid bodies?

I need a camera behind a player and I want this camera move with the player, but not going through environment or other players.
Environment and players are rigid bodies.

How can I do that ? A blend example would be nice :slight_smile:

Simple enough trick would be to attach small transparent plane diagonally to camera and enable rigidbody for it.

1 Like

thanks for your answer, but I can’t understand how it would work…
Is the plane a child of the camera ? I know that you can hide the plane in the visibility section : image
The camera has to be ideally placed behind the player, and move with it, so should the camera be a child of the player ?
How will the camera return at this place after a collision with a rigid body ?

I’m still searching, but I can’t currently find a solution…

Hi @mokauno,

One way I tried is this:

  1. Add a plane in front and at the back of your camera and parent both to the camera. Lets call it front plane and back plane
  2. make both the planes as RigidBodies, passive, and Box shape and disable rendering.
  3. Cast a ray from the player to the camera front plane, if it hits the camera front plane, do nothing. If it hits something else, move the camera closer to the player on its local axis.
  4. Now, ray cast from camera front plane to camera back plane. If it hits something, do nothing.
    Else, move the camera back to its original position.

I tried to achieve this using nodes only, but it seems the translate on local axis node does not respond as needed. Anyways, here is the blend file I tried.

NoWallHit.blend (1.2 MB)

Hope this helps.

Best regards,


Hi QC,
thanks for your effort, I’m amazed you provided a so hardworking answer.
I was thinking about something similar, but it was too much confuse for me to manage the problem.
The camera reaction on your example is weird, but it’s a good start point, and I will work on it.
Be sure I will share the final solution if I get one.
BTW, i always had problems with moving cameras along local axis. I believe cameras have a different coordinate system, note sure, but camera is facing -Z and that’s not for helping us. The solution I usually use is to parent the camera to an empty (that has good coordinates) and apply local transform to this parent.

I added a cone to the child of the camera to make it easier to understand the state of the camera, and tried to shoot with another camera.
NoWallHit2.blend (1.3 MB)

  1. It seems that depending on the position of the camera, the light beam may not hit the PlaneFront. Therefore, it changed so that a ray might be aimed at PlaneFront instead of PlaneBack.2
  2. The Translate Object node is set to move in the local z direction, but is actually moving in the local x direction. May need to fix the logic node, but as a temporary workaround, setting the value in the local -x direction seems to move in the local z direction.

But it is not perfect yet.


Hi @Sandy,

Thank you for the suggestions.

The only real issue I am stuck with is the moving on local axis when parented. As you stated in (2.), setting the value in x axis moves in local z direction. But if I then rotate the player and try again, it does not move on its local axis anymore.

It is this issue that I am referring to. And it needs to be fixed ASAP. The workaround posted by @Simonrazer in that thread also does not work.

Best regards,

1 Like

Same problems for me, can’t find a solution in this way.
So, does the camera really needs to be parented ? It could live it’s own life, always tracking the player with the “look at” node, then adjusting the distance with a ray cast just like in the solution of QC …
There could also be an empty parented to the player that represent the camera location if there is no obstacle. Then the camera could, on update, target this location…
The next problem would be that the “up of the camera” and the “up the the player” will have to point the same direction (stay on the same plane ?), especially if the player is a space ship…

Hello again,

So I just did a quick Haxe code for the thing. It now works much better. Please try and let me know:

Blend file:
NoWallHit3.blend (1.3 MB)

Haxe trait: (Place in /Sources/arm/)
CameraBmberHaxe.hx (1.3 KB)

Best regards,


I’m really sorry I can’t get it work. The console says :
Trace: TypeError: Cannot read property ‘transform’ of null
at Array. (:380:27)
at iron_App.update (:2532:27)
at kha_TimeTask.task (:25940:3)
at Function.kha_Scheduler.executeTimeTasks (:25824:75)
at Function.kha_Scheduler.executeFrame (:25776:17)
at kha_SystemImpl.renderCallback (:26579:16)


Interestingly enough, it works on my end when I re-downloaded the .blend and .hx it into a new folder.

The haxe trait CameraBmberHaxe.hx must be applied to the empty parented to the player object and not the camera.

The Player object must have just one trait enabled: PlayerContol

No other trait must be applied to any other objects.

Let me know if this helps.

Well, I got exactly the same error after deleting everything and downloading again, and checking…
Surely something on my system is wrong… I looked at your source code, it seems very similar to your previous node setup. Did you change something essential ?
If someone get this working, please tell…
I commented the section notifyOnUpdate, and got no error, so it’s there…
I get the error on : hit = physics.rayCast(,;
is there a try…catch to apply on this code ?

Did you re-download the new blend file?

Not sure what could be wrong, but here is a zip file for the same.

Download the zip file as a whole, simply unzip, open the blend file and run. Please try and let me know.

1 Like

Zip did the same error. I think physics.rayCast returns null and throw an exception. I don’t know why it works on your system, but you may you need to add a “try catch” on your code to catch the exception… Or maybe I need to update my system…

physics.rayCast should not return an error unless the objects player and planeFront don’t exist in the scene. I am totally lost now.

1 Like

Let get a rest man.
I think we focused too much of having a camera parented to the player, I will work at an other approach where the camera is free from the player.
If you get something on your way, let us know. You’re a boss.
Thanks :slight_smile:

1 Like

For me the code you write works perfectly. Using this code to modify the “Translate Object” and “Translate On Local Axis” nodes seems to solve the logic node problem as well.


Yes ! The haxe version works very well :smile:
I’m sorry, i needed to update Armory SDK to get it working.
QC and Sandy, your help was really useful, thanks ! :+1:

1 Like

I adapted QC’s work to have it working with logic nodes only, and without additional planes.
It’s also relative to the parent.
Here is it : NoWallHit_nodes.blend (1.3 MB)
Have a nice day :slight_smile:

1 Like