- Home /
Player Is able to rotate through walls.
So, My player Is set up so he kinda "bows" when he looks down, While "bowing" really fast and moving forward against a wall my player is able to glitch through the said wall, I am using "transform.eulerAngles" on the body (In fixedUpdate), I believe rotating the body through a rigidbody would work better but It seems having a rigidbody in any form as a child of another rigidbody (, The player GameObject) seems to just make It spazz out.
Things I have tried:
Making every collider convex.
Adding a sphere collider to the head.
Slowing movement and rotation (/ "bowing") speed based on distance to wall.
Clamping the maximum speed of rotation/"bow".
All of these seem to work pretty well together, But my player still spazzes out a lot so what I'm asking Is If there Is any "proper"/simpler way to achieve my goal?
Thank you for taking the time to read this :)
For a crude workaround, you could try adding a thicker collider to walls (it looks a little thin from your screenshot). Is there any other motion happening outside of FixedUpdate for this object?
Tried a thicker wall, Would need to be way way too thick to work sadly, All motion (movement/rotation) has been done In fixedUpdate.
Do you want the player pushed away from the wall when it bows or do you want the bow animation to stop when it's head hits the wall?
Does the player have a rigidbody? Because that would prevent the collider from existing in the same space as another collider.
Answer by MRswifting · Feb 21, 2018 at 11:32 PM
(Thank you @seandolan, Don't know how I missed it), So I managed to get It working amazingly with by using "OnCollisionStay" and "OnCollisionExit" to toggle a bool to disable then enable downwards camera (/ body) movement.
I think you meant to thank @RobAnthem ins$$anonymous$$d :)
No, I do mean you, "do you want the bow animation to stop when it's head hits the wall?" made me think of that solution.
Oh excellent then :) I love when sometimes on this Answer site, the result is that you get inspired to look at things a little different - which solves the problem. Glad this is not a "headache" for you anymore.
Answer by JonPQ · Feb 22, 2018 at 01:49 AM
aha! this is an age old physics problem. Easy solution.... not perfect. simplest one is to use one big bounding box/capsule/sphere that surrounds the player even when at maximum bow.
Lots of FPS shooters , have this problem also. (weapon passes through wall when character rotates) Their solution is to collide the body/capsule... and collide the gun separately and move the gun backwards along a vector along its length until not colliding any longer with the wall.
you could do this by having secondary collision during lateUpdate. after collision has finished. (detach collider and rigidbody from your character head) The 2 points come from a single node in character head, the 2 points are before and after character move, animation and collision. Then you do a SphereCast, from old to new position. (just like a raycast, but use a sphere of radius of the head) This will tell you if the head collided with anything as result of move. and will also tell you how far head moved before reaching collision.... and/or how far you'd have to move it back to get it back out of collision... At this point you have a couple of options... move the whole object back along the before->after vector... by the distance required to move the sphere out of the collision. just rotate or move the head back... or stop just any further bending forward (might be tricky) (or move it back to last valid bend angle) good luck take 2 world points