- Home /
I can't get my fpc to keep it's momentum
I created an fpc that wont be effected by gravity when it enters a trigger, but I can still use wasd to move around, and the character doesn't keep it's momentum. So I just need to be able to float through the zero gravity area and not be able to control you're movement.
public float speed = 10;
public Rigidbody rb;
public Vector3 jump;
public float jumpForce;
public bool jumping;
public Transform ground;
public static int pauseNo;
// Use this for initialization
void Start () {
Cursor.lockState = CursorLockMode.Locked;
rb = GetComponent<Rigidbody>();
jump = new Vector3(0.0f, 2.0f, 0.0f);
jumpForce = 2.0f;
jumping = false;
pauseNo = 1;
}
// Update is called once per frame
void Update () {
float transltaion = Input.GetAxis("Vertical") * speed;
float straffe = Input.GetAxis("Horizontal") * speed;
transform.Translate(straffe *Time.deltaTime, 0, transltaion *Time.deltaTime);
if (Input.GetKeyDown("escape"))
{
if (pauseNo == 1)
{
Cursor.lockState = CursorLockMode.Confined;
speed = 0;
pauseNo -= 1;
}
else
{
Cursor.lockState = CursorLockMode.Locked;
pauseNo = 1;
speed = 5;
}
}
if (Input.GetKeyDown("space") && jumping == false){
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
jumping = true;
}
if (Input.GetKey("left shift") && jumping == false)
{
speed = 10;
}
if (Input.GetKeyUp("left shift") && jumping == false)
{
speed = 5;
}
}
void OnTriggerEnter(Collider other)
{
if (other.name == "noGrav")
{
GetComponent<Rigidbody>().useGravity = false;
}
if (other.name == "ground")
{
jumping = false;
}
}
private void OnTriggerExit(Collider other)
{
if (other.name == "noGrav")
{
GetComponent<Rigidbody>().useGravity = true;
}
}
}
Comment