I am working on an RTS/city builder and want my camera to be able to collide with the terrain. Moreover, I want to restrict how far the camera can be moved out and I was planning to this with a blocking volume. This is my setup.
- A pawn that has a spring arm, a sphere collision and a camera.
- Moving the camera in game is done by moving the pawn using
Add Movement Input
- The camera is rotated in game by rotating the spring ar, by
Add Relative Rotation
- The zoom function is made by changing the
Target Arm Length
of the spring arm.
I don’t want my spring arm to handle collision as it will almost never be in the same location as my camera. Hence I have disabled Do Collision Test
for the Spring Arm (enabling it gives weird results with the camera jumping around and I believe its useful for 3rd person games but not here). That’s also the reason I added the sphere collision and was hoping for it to collide with the terrain and block the camera. But no such thing is happening.
I also don’t want the camera to move too far out so I was thinking of blocking it with an invisible wall blocking volume. It doesn’t work and the camera goes right through the invisible wall. Here’s a representation of what I am trying to do.
The gizmo is on the player start and the spring arm is long enough to be higher than the central mound. I am attempting to move the camera on the x axis towards the blocking volume and the camera goes right through it.
I think I didn’t setup my collision presets right. So here is what I have setup. This is the preset for the blocking volume
And this is the preset for the sphere collision inside the pawn
What am I doing wrong here?
EDIT: I just learnt that in order for a pawn to undergo collision, the collision component must be the root. But this is problematic as if I make the collision component the root, then the collision happens at the spring arm location and not at the camera location. That is why I ordered the pawn as Spring arm → sphere collider → camera so that the collider stays with the camera.