Home > Net >  I wrote code about the player's jump but it doesnt work
I wrote code about the player's jump but it doesnt work

Time:05-31

this is the code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class movement : MonoBehaviour
{
    private Rigidbody2D Rig;
    public float speed = 5;
    public float fallspeed = 2.5f;
    public float jamp = 1;
     void Start()
    {
        Rig = GetComponent<Rigidbody2D>();
    }

    void Update()
    {
     if (Input.GetKeyDown(KeyCode.W))
        {
            Rig.velocity = Vector2.up * jamp;
        }

        if (Rig.velocity.y < 0)
        {
            speed = 2.5f;
            Rig.velocity  = Vector2.up * Physics2D.gravity.y * (fallspeed -1) * Time.deltaTime;
        }
    }
}

a friend gave me the code so I don't know where the problem is because I just started programing

The speed is to move slower to the sides in the air...

CodePudding user response:

You dont have any keyCode to use you jump ?

if (Input.GetKeyDown(KeyCode.W))
        {
            Rig.velocity = Vector2.up * jamp;
        }

Do you want to use this part to make your character Jump ? When you press "w", maybe you have to increase the value of "Jamp" because Vector2.up * 1 won't change something.

CodePudding user response:

Since jamp only runs in one frame, it requires a high number. Increase the jamp number to about 300.

  • Related