Guest User

Untitled

a guest
Jun 20th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerMovement : MonoBehaviour
  6. {
  7.  
  8.     public Rigidbody rb;
  9.     public float forwardForce = 2500f;
  10.     public float sidewaysForce = 100f;
  11.     // Start is called before the first frame update
  12.     void Start()
  13.     {
  14.        
  15.     }
  16.  
  17.     // Update is called once per frame
  18.     void FixedUpdate()
  19.     {
  20.         rb.AddForce(0, 0, this.forwardForce * Time.deltaTime);
  21.  
  22.         if(Input.GetKey("d"))
  23.         {
  24.             rb.AddForce(this.sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
  25.         }
  26.         else if(Input.GetKey("a"))
  27.         {
  28.             rb.AddForce(-this.sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
  29.         }
  30.     }
  31. }
Add Comment
Please, Sign In to add comment