Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerController : MonoBehaviour
- {
- public float walkSpeed;
- Rigidbody rb;
- Vector3 moveDirection;
- // Use this for initialization
- void Awake()
- {
- rb = GetComponent<Rigidbody>();
- }
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Space))
- Jump();
- float horizontalMovement = Input.GetAxisRaw("Horizontal");
- float verticalMovement = Input.GetAxisRaw("Vertical");
- moveDirection = (horizontalMovement * transform.right + verticalMovement * transform.forward).normalized;
- }
- void FixedUpdate()
- {
- Move();
- }
- void Move()
- {
- Vector3 yVelFix = new Vector3(0, rb.velocity.y, 0);
- rb.velocity = moveDirection * walkSpeed * Time.deltaTime;
- rb.velocity += yVelFix;
- }
- void Jump()
- {
- rb.AddForce(new Vector3(0, 8, 0), ForceMode.Impulse);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement