Search Unity

Need help for jumping

Discussion in 'Scripting' started by Tonguesten, Jun 16, 2018.

  1. Tonguesten

    Tonguesten

    Joined:
    Aug 15, 2017
    Posts:
    24
    Hey guys so I am making a simple 2D platformer game with 3D asset, but I'm having a problem about jumping. So when I press 'W', it only ascending slowly while holding the 'W' button, what I want is when I press 'W', the player jumps instead of ascending awkwardly.
    Anyway here's the code snippet, its kinda simple right now:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Player : MonoBehaviour {
    6.  
    7.     public float h_speed = 10f;
    8.     public float v_height = 10f;
    9.  
    10.     // Use this for initialization
    11.     void Start () {
    12.        
    13.     }
    14.    
    15.     // Update is called once per frame
    16.     void Update ()
    17.     {
    18.         float horizontal = Input.GetAxis("Horizontal") * h_speed;
    19.         float vertical = Input.GetAxis("Vertical") * v_height;
    20.         Vector2 movement = new Vector2(horizontal, vertical);
    21.         transform.Translate(movement * Time.deltaTime);
    22.     }
    23. }
    24.  
    Plz help.
     
  2. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Have you followed the Unity tutorial about this?
     
  3. Tonguesten

    Tonguesten

    Joined:
    Aug 15, 2017
    Posts:
    24
    ok thx