Advertisement
Tarodev

Simple Player Movement - PlayerController.cs

Jun 14th, 2021
6,488
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.55 KB | None | 1 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerController : MonoBehaviour
  6. {
  7.     [SerializeField] private float _speed = 1;
  8.     [SerializeField] private Rigidbody _rb;
  9.     [SerializeField] private float _jumpForce = 300;
  10.    
  11.     void Update() {
  12.         var vel = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")) * _speed;
  13.         vel.y = _rb.velocity.y;
  14.         _rb.velocity = vel;
  15.  
  16.         if(Input.GetKeyDown(KeyCode.Space)) _rb.AddForce(Vector3.up * _jumpForce);
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement