Unity 2D Character Movement Horizontal and Jumping

Опубликовано: 30 Апрель 2026
на канале: NEYOVA
362
4

Unity 2D Character Movement Horizontal and Jump, jumping,


In this video, you can learn how an object moves and basically jump in unity. Here, a cube is provided to move left and right with unity c sharp codes " transform.Translate" on the horizontal axis and jumping with "AddForce" .


NOTE; Replace the parts that say "angel bracket here" in the code below with the angel bracket symbol.


Source codes are below ;




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

public class playercontroller : MonoBehaviour
{

public float speed = 8f;
public float jumpspeed = 400f;
private float horizontal;
private Rigidbody2D rgb;

// Start is called before the first frame update
void Start()
{
rgb = gameObject.GetComponent angle bracket here Rigidbody2D angle bracket here ();
}

// Update is called once per frame
void Update()
{

horizontal = Input.GetAxis("Horizontal") * speed * Time.deltaTime;

transform.Translate (horizontal,0,0);

if (Input.GetKeyDown(KeyCode.Space))
{

rgb.AddForce(new Vector2(0, jumpspeed));




}
}
}