Problem with collision
So here is my code
using UnityEngine; using System.Collections;
public class CarrinhoScript : MonoBehaviour {
private Rigidbody corpo;
// Use this for initialization
void Start () {
corpo = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update () {
if (Input.GetKey ("w")) {
transform.Translate (0, 0, -2);
}
if (Input.GetKey ("s")) {
transform.Translate (0, 0, 2);
}
if (Input.GetKey ("a")) {
transform.Rotate (Vector3.up, -2);
}
if (Input.GetKey ("d")) {
transform.Rotate (Vector3.up, 2);
}
it's a simple car, walking on the laps and all but then when it hits a lot of the walls it starts to flip and float in the air and i have no idea what's going on with this collision both y are fixed and the box collider is on the discrete mode
Answer by Oribow · Oct 04, 2015 at 03:42 PM
You should never move a "Rigidbody" with "transfrom.Rotate" or "transform.Translate". If you do that, you bypass the physics simulation of the object, causing unexpected movement. Only move "Rigidbody" by applying forces. Look at the script reference here.
Scripting
To control your Rigidbodies, you will primarily use scripts to add forces or torque. You do this by calling AddForce() and AddTorque() on the object’s Rigidbody. Remember that you shouldn’t be directly altering the object’s Transform when you are using physics
Your answer
Follow this Question
Related Questions
Problem with DontGoThroughThings script 0 Answers
Help With NavMesh 0 Answers
OnTriggerEnter not being called 2 Answers
Rotate camera on collision of character 1 Answer
Player passenger moving when being pushed by two platforms 0 Answers