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 3D

Rigidbody.AddForce(Vector3 force);Copy
Comment

How to jump in Unity using physics

Rigidbody.AddForce(Vector3 force);Copied!
Comment

PREVIOUS NEXT
Code Example
Csharp :: list of chars to string c# 
Csharp :: what is data encapsulation c# 
Csharp :: Editor log location unity 
Csharp :: inline list in c# 
Csharp :: http error 502.5 asp.net core 2.2 
Csharp :: csharp check if env is development 
Csharp :: public GameObject 
Csharp :: c# clear a textbox 
Csharp :: regular expression for website url validation in c# 
Csharp :: validate data exist in database lara vel 
Csharp :: how to add a list to observablecollection in c# 
Csharp :: unity instantiate with name 
Csharp :: c# entity framework code first connection string 
Csharp :: instantiate iqueryable c# 
Csharp :: c# date 
Csharp :: how to reference a child object unity 
Csharp :: generate random name c# 
Csharp :: how to sort string array alphabetically in c# 
Csharp :: c# difference between two dates in milliseconds C# 
Csharp :: c# datetime remove time 
Csharp :: convert ienumerable to list 
Csharp :: c# datagridview filter textbox 
Csharp :: how to move a gameobject to another object 
Csharp :: unity movement 
Csharp :: clear controls from panel c# 
Csharp :: c# get getter set setter method 
Csharp :: c# day of week number 
Csharp :: access to element in object c# 
Csharp :: google sheet script change text color 
Csharp :: function in c# to do addition 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =