I am putting a collision sphere and camera as a child of a spring arm. This spring arm is attached to the player actor. I need to detect when the camera is overlapping other objects such as walls, and I have set up the collision profiles to allow this to take place. The only issue so far is that the sphere collider is only detecting the overlap when the player is moving.
I have scoured a few forum posts about the same topic, but every forum post had a work around that was unique to each specific case instead of a solution that will work for me.
I’m assuming something in Unreal’s class system “disables” the collision detection of the character and all children of it when not moving for efficiency, but I don’t see any settings to remove it so far.
Can anyone help me get on the right path to accomplish this?
If it helps: I am figuring this out for a camera system operating similarly to Mario Odyssey. The “Do Collisions Check” on the spring arm doesn’t fit my needs (arm itself acts as the collider) so I am building my own camera collision system.
I guess for a collision to happen, two or more objects must collide and at least one of them should be moving. I never thought that collision wouldn’t run if an object wasn’t moving but I guess it would make sense - the other object should be moving though for a collision to happen (if neither are moving how can they collide?).
In your case, if the player isn’t moving, I assume the camera is moving around the player and you want that checked for collision? That should pickup collision though.
If all objects are still (camera, player, wall) but you just need to check if one overlaps the other the only other thing I can think of is turning the collision off/on at that point as that will likely force check for a collision. Or just running a sphere overlap at that point?
You are correct in that the player and wall are still while the camera is moving, but the camera moving is not making the collision be detected. It’s possible that this is because it is parented to a spring arm? I might have to test that out when I have the chance.
Yesterday I looked into using the “overlapping actors” node every tick and then tracing a line to the mesh and setting the spring arm length to the distance to the closest one, but this jitters and only runs a few times a second rather than every frame like I would like.
Oh yeah definitely don’t run get overlapping actors every tick - that’s an expensive operation.
If your camera is moving and you have a collider on it though it should definitely pick up any collisions. Maybe just double check your collision settings on the collider itself.
Yep I’ve triple checked them, they collide but only when the player is moving. I think I will try making the camera its own actor rather than a child of the player and see if the collisions will work appropriately that way.
Definitely seems odd. Colliders should work fine even if children, as long as something is moving. Interesting to see if making it a separate actor fixes.
I have been having the same issue. I looked into using hits instead of overlaps to check collision but still had the same issues.
Just out of curiosity, is your root component your character’s capsule collider? I sorta stupidly did this a long time ago and it has been an annoyance with certain collision based work since. I wondered if that had anything to do with the collider on my spring arm only overlapping when the character is moving.
The spring arm doesn’t use “collision” it uses camera channel ray casts, which are run every frame and do not get disabled.
What object comes between the camera and the player when the player is standing still?
If that object comes between the camera and the player when the player is moving, is the collision detected?
My guess is that the object that is blocking the camera when the player is standing still, is not marked to block camera/view ray checks in its collision properties, and it so happens that you only find that object gets in the way when the player is standing still.
If that doesn’t help, the post a screen shot of the setup when the object is blocking (ideally with collision visualization turned on,) and of the character/camera/arm setup.
Hello, I actually don’t want the camera/spring arm to zoom in when there is an object between the camera and the player, but rather have the cameras sphere component itself collide with things similar to how it works in Mario Odyssey. The spring arm is currently only being used for the “target arm length” and “lag” settings, and the collisions ideally should being done separately.
In trying to fix this I tried making the sphere collider and the wall I’m using for testing block each other in collision settings(instead of overlap) but they still go right through. When using overlaps they work when player is not moving, when using block it does not work at all.
Video showing setup: https://youtu.be/Fz68Zl-64K4
I’m a student and I don’t have time to look up/into how to turn on Unreal’s collision visualization, but in the video its my most recent endeavor with using “block” on the colliders. Before this I tried using overlap and then manually setting the position of the camera with a hit when an overlap was detected, but that was too jittery so I scrapped it even though it worked.
The only thing I have not tried yet that I think might work would be to make the camera itself a separate object, but that would also take a lot of time to implement so I would probably test that in a separate project file.
I am learning Unreal Engine from Unity and it sucks that I’m having such trouble with something that would only take me 5 minutes in an engine I’m more used to ;-;. This is a project for portfolio work so for now I have just conceded and am using the default spring arm collision functionality and accept that my camera is just gonna have to be subpar until I find a solution.
Yes, the capsule component is the default scene root of any character, correct? Or is this not best practice? I’m relatively new to Unreal Engine, does the default scene root of an actor replace all other collisions or something? If so, that would explain a lot and confirm that making the camera a separate actor might be a workaround to this issue.
The Character class has a capsule as the root always, yes.
The Spring Arm will try to glue the camera to the position it finds. If you want the camera to have a lag, you must use another mechanism to control the camera, or another camera entirely.
What I would do, would be to create a new Actor that has a Camera component. I would spawn this Camera from the begin play of the Character, and assign it to some variable. Then I would tell the player controller to use this Camera actor as the “View Target” (using “Set View Target with Blend” which is possibly the worst named function in the engine)
“View Target” means “the thing that contains and targets the camera”
THEN I would make the Camera actor implement the movement with lag in its Tick function. You can make it have a sphere collider, and then update its position towards some desired location, but using collision – probably turn on simulate physics, turn off gravity, and use forces to drive it towards the location.
You’ll want to calculate “where ought it to be?” as the goal each frame, and then calculate “where will the camera be 300 milliseconds from now?” based on position/velocity, and then add a force dependent on the difference in position between those two points, each tick. (This is a classic P/D controller in control theory, btw. If you want something to google for!)
Thanks, I’ll definitely try making it its own separate actor as soon as I can. Luckily I already have the majority of the code for the Tick function of the controller to do custom lag, as I already made a cam target with custom lerping. The “Set View with Blend” I agree is quite a ridiculous name. Before building the project I first tried to make the camera seperate but the character was defaulting to a newly spawned cam, probably because I didn’t have the set view target going on. Thanks! I’ll update the thread as soon as I have the opportunity to try this out