- Home /
Capsule Collider moving through vertical terrain
After the recent physics engine updates and terrain changes, my collider has started to go through vertical terrain, but will stay on flat terrain.
Here is my code for moving my character
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D) ) { GetComponent<Rigidbody>().MovePosition(transform.position + (transform.right * MoveSpeed * Time.deltaTime * Input.GetAxis("Horizontal")) + transform.forward * MoveSpeed * Time.deltaTime * Input.GetAxis("Vertical")); Run = false; }
Could someone please help me out, my game is crucial to being to explore and not walk through walls. Another thing to note is I tried to shoot a ray cast to stop the player if they got close to a wall however it didn't work. This is the code for that
RaycastHit hitInfo; if (Physics.SphereCast(transform.position, m_Capsule.radius * (1.0f - advancedSettings.shellOffset), Vector3.down, out hitInfo, ((m_Capsule.height / 2f) - m_Capsule.radius) + advancedSettings.stickToGroundHelperDistance, Physics.AllLayers, QueryTriggerInteraction.Ignore)) { if (Mathf.Abs(Vector3.Angle(hitInfo.normal, Vector3.up)) < 85f) { m_RigidBody.velocity = Vector3.ProjectOnPlane(m_RigidBody.velocity, hitInfo.normal); } }
I had taken it from the unity default rigid body fps player and tried to get it to work, while it worked if i was walking very slow, if i ran I would just end up going straight through the wall.
Your answer
Follow this Question
Related Questions
Capsule collider going through terrain collider 1 Answer
Terrain heightmap resolution affects collision calculation 0 Answers
How to restrict building on uneven surfaces? 2 Answers
How to change the capsule's height without deforming it? 2 Answers
Mobile Build and Playmode Terrain Collision Disparity 0 Answers