Answers for "jump cube in unity"

C#
1

how to make a cube jump in unity

using UnityEngine;
 using System.Collections;
     
     [RequireComponent(typeof(Rigidbody))]
     public class PlayerController : MonoBehaviour {
     
         public Vector3 jump;
         public float jumpForce = 2.0f;
     
         public bool isGrounded;
         Rigidbody rb;
         void Start(){
             rb = GetComponent<Rigidbody>();
             jump = new Vector3(0.0f, 2.0f, 0.0f);
         }
     
         void OnCollisionStay()
         {
             isGrounded = true;
         }
     
         void Update(){
             if(Input.GetKeyDown(KeyCode.Space) && isGrounded){
     
                 rb.AddForce(jump * jumpForce, ForceMode.Impulse);
                 isGrounded = false;
             }
         }
     }
Posted by: Guest on February-23-2021
0

how to make a cube jump in unity

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test : MonoBehaviour
{

    Rigidbody rb;

    // Start is called before the first frame update
    void Start()
    {
       rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Space))
        {
            rb.AddForce(Vector3.up * 500f);
        }
    }
}
Posted by: Guest on February-23-2021

C# Answers by Framework

Browse Popular Code Answers by Language