The question is answered, right answer was accepted
GameObject fall Slowly [C#]
Hey eveybody ! Today i'm making a car. Alls my 3D gameObjects are in an Empty GameObject who have the rigidbody (with 1000 in Mass) and my playerControler. But the fact is that my GameObject fall very Slowly and i check on the internet but nothing work....
this is my script :
using UnityEngine; using System.Collections; using UnityEngine.Networking;
public class PlayerControler : NetworkBehaviour { Transform trans; // Used to cache the transform Rigidbody body; // Used to cache the RigidBody float hInput; float vInput; float rotationSpeed = 90f; // float fallVelocity; public GameObject phareGauche; public GameObject phareDroit;
void Awake()
{
trans = transform;
body = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (isLocalPlayer == false) return;// Don't check input if this isn't running
// on the local player object
/*fallVelocity = gameObject.GetComponent<Rigidbody>().velocity.z;
gameObject.GetComponent<Rigidbody>().velocity += Vector3.down * fallVelocity;*/
if (Input.GetAxis("Vertical") < 0)
{
phareDroit.GetComponent<Renderer>().material.color = new Color(255f, 142f, 0f);
phareGauche.GetComponent<Renderer>().material.color = new Color(255f, 142f, 0f);
} else
{
phareDroit.GetComponent<Renderer>().material.color = new Color(214f, 217f, 224f);
phareGauche.GetComponent<Renderer>().material.color = new Color(214f, 217f, 224f);
}
hInput = Input.GetAxis("Horizontal");
vInput = Input.GetAxis("Vertical");
}
void FixedUpdate()
{
if (isLocalPlayer == false) return;// Don't check input if this isn't running
// on the local player object
// Remove unwanted forces resulting from collisions
body.velocity = Vector3.zero;
body.angularVelocity = Vector3.zero;
// Handle rotation
var rot = body.rotation.eulerAngles;
rot.y += hInput * rotationSpeed * Time.deltaTime;
body.MoveRotation(Quaternion.Euler(rot));
// Handle forward movement
body.MovePosition(body.position + vInput * trans.forward * 5f * Time.deltaTime);
}
}
Thank you, bye !
This is a sign that the scale of everything is too large.
$$anonymous$$aybe, it is a car in a town (some blocks are greater than 100 units)
Answer by tanoshimi · Feb 15, 2016 at 01:01 PM
Your code is somewhat confusing - you're using rigidbodies which suggests you want to let the physics engine calculate the simulation, but then you're overriding the physics engine on every step by setting:
body.velocity = Vector3.zero;
body.angularVelocity = Vector3.zero;
and then manually calculating the movement and rotation of the object....?
You need to pick one approach or the other - if you want to move the object, set the rigidbody to kinematic and calculate all the forces yourself. If you want to use the physics engine, don't then override it.
Lol I didnt read the code. Setting velocity = zero 50 times a second is a sure way to make your objects fall mega slowly.
Thank you (tanoshimi and meat5000) to answer me very quickly ! So, i deleted this two lines :
body.velocity = Vector3.zero; body.angularVelocity = Vector3.zero;
and it work !
I promise that is my next code i will make more description in case i need some help !
Thank you again, bye !