- Home /
Question by
unity_2nsLdoOrP3IXWw · Jul 08, 2020 at 08:28 PM ·
rigidbodystop
How to stop my rigidbody immediatly when pressing Q,Im trying to stop my rigid body immediatly when pressing Q
This is the code
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq.Expressions;
using UnityEngine;
public class Dash : MonoBehaviour {
float cooldown ; //Cooldown added to prevent double jump
// Use this for initialization
void Start () {
cooldown = 0;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Space) && cooldown < 0) // Jump if the cooldown ended
{
GetComponent<Rigidbody>().AddForce(new Vector3(0, 300, 0));
cooldown = 2;
}
else
{
cooldown = cooldown - 1 * Time.deltaTime;
}
if (Input.GetKeyDown(KeyCode.Q)) // Where I would like your help
{
}
}
}
Comment
Best Answer
Answer by unity_ek98vnTRplGj8Q · Jul 08, 2020 at 09:11 PM
Try GetComponent<Rigidbody>().velocity = Vector3.zero;
Thank you it worked, I just switch the GetKeyDown with GetKey, cause with the down it would just slow it down a bit Again thanks
Your answer