I am trying to create a script where I can move a ball, horizontally, and vertical. I have been able to do this work.
But now I want to "jump" my ball I ended up with the script, but now my ball just started like a rocket xD
Does anyone help me
using UnityEngine; Using System.Collections; Public Category PlayerController: MonobeHawk {Speed of public float; JumpSpeed public float; Public GUIText countText; Public GUIText winning text; Private count; Zero starting () {count = 0; SetCountText (); WinText.text = ""; } Fixed upload (zero) () {float move horizontal = input Getexis ("horizontal"); Float moveVertical = Input.GetAxis ("workspace"); Vector 3 movement = new vector 3 (Hillhurst, 0, running); Vector 3 jump = new vector 3 (0, jump speed, 0); GetComponent & lt; Rigidbody & gt; (). AddForce (Movement * Speed * Time.deltaTime); If (Input.GetButtonDown ("Jump")); GetComponent & lt; Rigidbody & gt; (). AddForce (jump * jumpSpeed * Time.deltaTime); } Zero OnTriggerEnter (collider other) {if (other.gameObject.tag == "pickup") {other.gameObject.SetActive (wrong); Calculation = count 1; SetCountText (); }} Zero setCountText () {countText.text = "count:" + count.ToString (); If (calculation> = 10) {winText.text = "you won!"; Jumping with a constant force on one object does not work.}}}}
bool jumping; If (input. Gatebuttondown ("jump") & amp;;! This.jumping); {GetComponent & lt; Rigidbody & gt; (). AddForce (jumpForce * new vector 3 (0,1,0)); This.jumping = true; }
Also keep in mind that in your example, you are multiplying the upper unit vector by jumpspeed on both sides, once in the jump
vector in the initialization and then once < Code> AddForce in the method
Of course, you also need to make sure that the gravitational pull applies to the object back down (and if the object hits the ground, then reset the jump boole.
Normal As a matter of fact, what type of game are you making, it is easy to set the velocity of the object only and not to move a few simple steps to work with a simple physics engine.
No comments:
Post a Comment