how to add jump in snow boarder …i try but the player jump but i adjust value even though it jump in same hight
Hi,
I’m not sure if I understood you correctly but does the player jump?
i adjust value even though it jump in same hight
In the TileVania section, we make the player jump. Maybe you could watch that video. It’s called “Jumpy Jump”.
Also please feel free to ask our helpful community of students for further advice over on our Discord chat server.
See also:
- Forum User Guides : How to mark a topic as solved
Hi Joshua,
don’t know if you still need answers, but I’ll give it a go.
As I understand, if you press jump, the jump height does not change, regarding to what values you change.
It would be helpful if you shared some code, but here is my simple jump code you could study and use.
I find the code self explanatory, but if you need extra info, just ask.
(for simplicity, I took out irrelevant code that you already should have from this course and left only the script).
Take care.
public class PlayerController : MonoBehaviour
{
// ...Removed for simplicity
[SerializeField] float jumpForce = 2f;
[SerializeField] float xJump = 0f;
[SerializeField] float yJump = 2f;
bool isGrounded;
Vector2 jump;
// Start is called before the first frame update
void Start(){
// .. Removed for simplicity
jump = new Vector2(xJump, yJump);
}
// Update is called once per frame
void Update(){
if (canMove){
// ... Removed for simplicity
AddJump();
}
}
// AddJump ads an Impulse to make player jump when pressing "space" key
void AddJump(){
if (Input.GetKey(KeyCode.Space) && isGrounded) {
rb2d.AddForce(jump * jumpForce, ForceMode2D.Impulse);
isGrounded = false;
}
}
// OnCollisionStay2D sets isGrounded to true if player is touching the Surface Effector 2D
// to avoid infinite jumps
void OnCollisionStay2D(Collision2D other) {
isGrounded = true;
}
}
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.