Hey guys i try to write a controller script with a rigidbody and i dont want to silde that much i want to smoothdamp the velocity to zero but i stick one step before. something is wrong and im pretty sure its the line at the ent where i give rigidbody.velocty the relative velocity… pls help me that would be awesome
using UnityEngine;
using System.Collections;
public class PlayerControl : MonoBehaviour {
public float power = 20.0f;
public float maxspeed=20f;
public float breakSmoothness=20f;
public Vector3 movementForce;
public CameraControl cameraHead;
public Vector3 relativeVelocity;
float reVelocity;
void FixedUpdate (){
movementForce = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical")) * power;
rigidbody.rotation = Quaternion.Euler (0, cameraHead.currentYrotation, 0);
rigidbody.AddRelativeForce (movementForce);
relativeVelocity = transform.InverseTransformDirection (rigidbody.velocity);
relativeVelocity = new Vector3 (Mathf.Clamp (relativeVelocity.x, maxspeed * -0.75f, maxspeed * 0.75f),
relativeVelocity.y,
Mathf.Clamp (relativeVelocity.z, maxspeed * -1, maxspeed));
if (movementForce.z == 0)
relativeVelocity.z = 0;
if (movementForce.x == 0)
relativeVelocity.x = 0;
rigidbody.velocity = relativeVelocity;
}
}