- Home /
My vehicle goes through walls and floors disregarding all colliders
I have a vehicle for a game I am making, and it can go through anything, it is supposed to not be able to go through the floor or walls but it does. I have colliders on all my objects and multiple colliders on objects that are triggered.
Here is the Script:
public Transform ufoPos; public GameObject UFOPrefab; public GameObject PlayerPrefab; public float rotateSpeed;
void OnTriggerEnter (Collider other) {
GetComponent<ufoMovement>().enabled = true;
PlayerPrefab.SetActive(false);
}
void Update () {
var x = Input.GetAxis ("Vertical");
var y = Input.GetAxis ("Horizontal");
transform.Translate (0,x,y);
if (Input.GetKey(KeyCode.E)) {
transform.Rotate(0,0,rotateSpeed);
} if (Input.GetKey(KeyCode.X)) {
PlayerPrefab.transform.position = ufoPos.position;
GetComponent<ufoMovement>().enabled = false;
PlayerPrefab.SetActive(true);
}
}
What are your rigidbody settings? Also Translate is a direct movement, try AddRelativeForce ins$$anonymous$$d to stop any clipping.
GetComponent<Rigidbody>().AddRelativeForce(new Vector3(0,x,y));
Answer by MounirDev · Jul 31, 2019 at 07:53 PM
make sure Is Trigger is unchecked in both game objects. if yes, make sure they both have rigidbody set to dynamic and set the gravity to 0.
@$$anonymous$$ounirDev Yes on all of that and it still goes right through objects as if they are not there
Your answer
![](https://koobas.hobune.stream/wayback/20220612205758im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why the npc character walking strange when using a Rigidbody and Is Kinematic on enabled ? 1 Answer
How to check if two objects collide without a collider 1 Answer
What is the cheapest way to prevent object A from going through object B 3 Answers
Avoid Player bouncing when colliding with objects 3D 1 Answer