movement
Thu Sep 17 2020 19:10:38 GMT+0000 (Coordinated Universal Time)
Saved by
@re11
private bool grounded = true;
public float jumpPower = 190;
public float Power = 10f;
private bool hasJumped = false;
public Rigidbody rb;
// Use this for initialization
void Start ()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update ()
{
// Do something
if(!grounded && rb.velocity.y == 0) {
grounded = true;
}
if (Input.GetKey (KeyCode.W) && grounded == true) {
hasJumped = true;
}
if (Input.GetKey(KeyCode.D))
{
transform.Translate(Vector3.right * Power * Time.deltaTime, Space.World);
}
if (Input.GetKey(KeyCode.A))
{
transform.Translate(Vector3.right * -Power * Time.deltaTime, Space.World);
}
}
void FixedUpdate (){
if(hasJumped){
rb.AddForce (transform.up*jumpPower);
grounded = false;
hasJumped = false;
}
}
content_copyCOPY
Comments