Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

how to make an object jump in unity

Rigidbody rb;
float force = 10f;

void Awake(){
  rb = GetComponent<Rigidbody>();
}

void Update(){
   if(Input.GetKeyDown(KeyCode.Space)) {
      rb.AddForce(Vector3.up * force, ForceMode.Impulse);
   }
}
Comment

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;
        }
    }
}
Comment

How to jump in Unity using physics

Rigidbody.AddForce(Vector3 force);Copied!
Comment

PREVIOUS NEXT
Code Example
Csharp :: convert iformfile to byte array c# 
Csharp :: how to split concat string c# 
Csharp :: c# string array to string 
Csharp :: 2d topdown movement unity 
Csharp :: how to make a mouse down condition in unity 
Csharp :: how to create a file through c# script 
Csharp :: get current playing animation of animator unity 
Csharp :: how to check a list is null or empty in c# 
Csharp :: 2d list in c# 
Csharp :: discord bot in c# 
Csharp :: razor confirm password validation 
Csharp :: xamarin hide back button 
Csharp :: how to make panel scrollable c# 
Csharp :: random.range unity not working 
Csharp :: c# get datatable column names to list 
Csharp :: c# mathf.ceiling 
Csharp :: if in dictionary c# 
Csharp :: how to install jdk on linux manjaro 
Csharp :: move files from one directory to another using c# 
Csharp :: c# unity 
Csharp :: how to see image from website in wpf 
Csharp :: c# dictionary get value by key 
Csharp :: parse datetime c# 
Csharp :: badlion 
Csharp :: {"The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."} 
Csharp :: unity button press 
Csharp :: raylib c# basic window 
Csharp :: c# performance timer 
Csharp :: C# default value for datetime parameter 
Csharp :: unity interfaces 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =