I'm talking about something like from Alien Isolation. I having a kinematic body on the camera but when I rotate the body the camera passes though the environment. How can the camera not phase through the environment but still try to go back to the location that it is supposed to be in.
I am quite aware this might be horribly worded so I took a video as an example of the leaning mechanics I want to emulate.
In your case, what I would do is make the player of a parent node and have the slerp code put on the parent when you press the key then it should slerp the player past a wall or whatever obstacle you have. By the way the reason I would do it with a parent rather than the player itself is the slerp might just rotate the player object rather than move it but I haven't properly tested this myself you'll need to tweak things according to how you want it.
To get an idea of how to implement this generally there's also a lerp tutorial I've used myself for aiming down sights, same principle, just different maths.
Thank you but I already have a system that allows for the head to properly tilt and move in the direction that I want it to.
The system that I have is:
-> Kinematic Body
--> Collision shape
--> Tween
--> Rigid Body
---> Collision shape
---> Camera
The kinematic body is the main body of the character. I use it to rotate the player when they want to look left or right. In the original video when the player leans and starts to look around a corner they collided with the corner. However, when I rotate the kinematic body while the rigid body is leaning out, the rigid body doesn't handle any collisions or it handles them improperly.
I took an overhead video of the problem that I am facing.
Sorry for describing my problem correctly in the first post.
Edit: I realized I didn't point out the problem. When the body is rotating the rigid body phases through collisions. Only when the kinematic body stops rotating does the rigid body handle collision detection.
Sorry, my bad, I was tired and I wasn't paying attention, the problem with the clipping you have is the fact that your rigidbody is kinematic. If you want the collisions to happen disable kinematic and the collisions should work, you also potentially need more accurate collision on your player itself to make sure there's no clipping at all.
If you don't want the rigidbody to respond to physics and so on you will need to have it activate that when you want it in code.
I'm not sure I'm able to do that. The problem isn't the kinematic body and the rigid body colliding. The way this is set up is the kinematic body is the main body of the character. The kinematic handles the players gravity, the movement and pretty much everything else dealing with physics. The rigid body is the head. I want to be able to move just the head (Sphere in the picture) away from the body.
The problem comes when I want to "peak" around corners. I figured I should rotate the head around the body rather than rotating the head locally. Almost like the head is orbiting the body to make a sphere. However, when I rotate the body the head phases through all collisions instead of colliding. The second video shows the problem of the head only colliding when the body stops rotating and the head not colliding at all when the body is rotating. I'm not sure why collisions aren't handled and that is what I'm trying to solve.
I'm not entirely sure how to send a project but I made a github page. It is in C# as that is my primary language.
https://github.com/Holo74/LeaningDemo
Hopefully this shows my problem better than my video or my descriptions.
This is a pretty detailed problem, my main knowledge is in Unity and I've only just recently learned Godot but usually these kinds of clipping problems indicate either the rigidbody is going too fast so it's 'glitching' through the collider or there's some other issue involving the FPS.
Have you tried making the colliders bigger and thicker? Unfortunately this is one of the struggles of games development where you have to keep experimenting and find out what works for your particular idea.
I would think it has something to do with the collider but honestly it seems like when the parent is moving then it disables physics on any child objects. I even noticed that when gravity on the rigid body was enabled that it would stop falling when the body (parent object) would start to rotate. Maybe the solution is to have a the head not be a child of the body and only have the desired head location be the child of the body. Then you would just move and slide the head to the desired location. This could mean a lot of lag on the camera's side and but it might be a possible solution. This would probably introduce a lot of problems but at least the head would be able to collide with things.
Hang on, I just had an idea when I woke up, have you considered maybe changing the velocity of the body and moving it that way rather than directly interfering with the rotation or position? It may be that's what is throwing off the collision, could be worth a shot just to see.
So I changed the kinematic body to a rigid and applied a angular velocity to it. Not only did the head and body fly off but they also had no collisions with anything at all. I'm starting to think that something major is broken or the problem is me.
LOL yikes, yeah that sounds like something weird is going on, you're probably going to have to see if someone with more experience to see what can be done. You never know, you could have stumbled on a strange bug given Godot is open source.
So, definitely was me. I found out that I changed one of the collision masks with the players body and once I changed it back then everything was all good. I also tried a different method where instead of having the head be rotated rotated I would have a point that the head would move towards. It works a little better but there is something really off with my code and the head flies off into space only to return to where it is supposed to. Maybe when the answer to this problem is finally worked out you could make a video on it seeing how you make some really good videos and this might help others to know the solution.
I should stress even though I've got 5 years on Unity I'm still learning with Godot so I think it will be a good idea just to see if anyone more experienced knows anything more about this issue but at least you solved it yourself for the most part.
For anyone that has the same problem. Here is how I solved the problem.
Have a position3d that in your character. When you go to lean use a Tween node that moves the position 3d into the desired position. Have the Tween node also rotate the camera to your desired position. Then active a script that makes the head move and slide to the desired position.
I found that using the local transform had many issues and I wasn't smart enough to solve them, so instead I used the global positions of both the head and the desired position to get the direction.
The equation was desired point - current point = direction
Hopefully this helps someone in the future because this was an absolute pain to figure out and I'm willing to bet there are more problems but this solution works somewhat.