Advertisement
Dani_info

unity forces

Mar 1st, 2018
110
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerController : MonoBehaviour {
  6.  
  7.     public Rigidbody rb;
  8.     [SerializeField] private float force;
  9.     [SerializeField] private Transform cameraPos;
  10.     [SerializeField] private Vector3 difference;
  11.     // Use this for initialization
  12.     void Start () {
  13.         rb = GetComponent<Rigidbody>();
  14.        
  15.     }
  16.    
  17.     // Update is called once per frame
  18.     void Update ()
  19.     {
  20.         if (Input.GetKey("d"))
  21.         {
  22.             rb.AddForce(force * Time.deltaTime, 0f, 0f, ForceMode.Impulse);
  23.         }
  24.         if(Input.GetKey("a"))
  25.         {
  26.             rb.AddForce(-force * Time.deltaTime, 0f, 0f, ForceMode.Impulse);
  27.         }
  28.         if (Input.GetKey("w"))
  29.         {
  30.             rb.AddForce(0f, 0f, force * Time.deltaTime, ForceMode.Impulse);
  31.         }
  32.         if (Input.GetKey("s"))
  33.         {
  34.             rb.AddForce(0f, 0f, -force * Time.deltaTime, ForceMode.Impulse);
  35.         }
  36.  
  37.     }
  38. }
Advertisement
RAW Paste Data Copied
Advertisement