How do I keep the player with rigidbody from going through the wall
My problem is that when the player hits a wall, it ignores it as if it is not an object. both objects have a collider and the player has a rigidbody. This is my script
c#
using UnityEngine; using System.Collections;
public class Game : MonoBehaviour {
public float speed = 0.3f;
public Rigidbody rb;
public GameObject floor;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.D)) {
rb.MovePosition(transform.position + transform.forward * speed);
} else if (Input.GetKey (KeyCode.A)) {
rb.MovePosition(transform.position - transform.forward * speed);
}
if (Input.GetKey (KeyCode.Space)) {
Destroy (floor);
}
}
}
If you collision detection is not continuous and/or your wall's collider is thin, that could happen.
Answer by Pharan · Oct 20, 2015 at 07:06 PM
If your character isn't moving too fast, and its collider and the wall collider's layers are set to collide.
Your character might ignore other colliders if your character's rigidbody is kinematic.
Your answer
Follow this Question
Related Questions
c# jumping isn't consistent, please help 0 Answers
I added Rigidbody to my cube and now it goes super fast when i move! 0 Answers
Question about NavMesh and Rigidbody 0 Answers
How to apply a force at certain point of an object? 0 Answers
C# keep previous velocity while jumping, previous solutions not working 0 Answers