Advertisement
Guest User

Movement

a guest
Sep 29th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerMovementTest1 : MonoBehaviour {
  5.     public float speed;
  6.     public float rotationSpeed;
  7.  
  8.     Vector3 rotation;
  9.     Rigidbody rb;
  10.     float horizontal;
  11.     float vertical;
  12.  
  13.     // Use this for initialization
  14.     void Start () {
  15.         rb = GetComponent<Rigidbody>();
  16.     }
  17.    
  18.     // Update is called once per frame
  19.     void Update () {
  20.         rotation = new Vector3(0f, Input.GetAxis("Horizontal2"), 0f);
  21.         horizontal = Input.GetAxis("Horizontal");
  22.         vertical = Input.GetAxis("Vertical");
  23.     }
  24.  
  25.     void FixedUpdate()
  26.     {
  27.         rb.MoveRotation(transform.rotation * Quaternion.Euler(rotation * rotationSpeed));
  28.         rb.MovePosition(rb.position + (transform.forward * vertical) * speed);
  29.         rb.MovePosition(rb.position + (transform.right * horizontal) * speed);
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement