Unity Jump Script?

1 Antwort

public float jumpHeight = 7f;
 public bool isGrounded;
 
 private Rigidbody rb;
 
 void Start()
 {
  rb = GetComponent<Rigidbody>();
 }
 
 void Update()
 {
    if (isGrounded)
    {
       if (Input.GetButtonDown("Jump"))
       {
       rb.AddForce(Vector3.up * jumpHeight)
       }
    }
 }
 
 void OnCollisionEnter(Collision other)
 {
     if (other.gameObject.tag == "Ground")
     {
         isGrounded = true;
     }
 }
 
 void OnCollisionExit(Collision other)
 {
     if (other.gameObject.tag == "Ground")
     {
         isGrounded = false;
     }
 }

Woher ich das weiß:Recherche

HackerDatei 
Fragesteller
 08.05.2022, 16:13

wie soll ich das in mein script einfügen ? :D

0
Pywald  08.05.2022, 16:25
@HackerDatei
public float jumpHeight = 7f;
public bool isGrounded;
private Rigidbody rb;
rb = GetComponent<Rigidbody>();
if (other.gameObject.tag == "Ground")
     {
         isGrounded = true;
     }
if (other.gameObject.tag == "Ground")
     {
         isGrounded = false;
     }
if (isGrounded)
    {
       if (Input.GetButtonDown("Jump"))
       {
       rb.AddForce(Vector3.up * jumpHeight)
       }
    }

Vorsicht ungetestet!

Füge den Code zur Update-Funktion hinzu und gib dem zum Boden den Tag „Ground“

0
HackerDatei 
Fragesteller
 08.05.2022, 16:29
@Pywald

ich habe immer noch meine Probleme damit könntest du mir das ganze Script senden , also mit Import usw.

0
Jannik947  08.05.2022, 17:36
@HackerDatei

Was für ein Problem gibt es denn? Schick doch bitte mal einen Screenshot von den Fehlern.

0