duck

Player World Axis Control

Mar 2nd, 2016
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerWorldAxisControl : MonoBehaviour
  5. {
  6.  
  7.     Rigidbody rb;
  8.     public float moveSpeed = 5;
  9.  
  10.     // Use this for initialization
  11.     void Start()
  12.     {
  13.         rb = GetComponent<Rigidbody>();
  14.     }
  15.  
  16.     // Update is called once per frame
  17.     void Update()
  18.     {
  19.         float h = Input.GetAxis("Horizontal");
  20.         float v = Input.GetAxis("Vertical");
  21.  
  22.         float fallSpeed = rb.velocity.y;
  23.  
  24.         Vector3 newVelocity = new Vector3(h, 0, v) * moveSpeed;
  25.         newVelocity.y = fallSpeed;
  26.         rb.velocity = newVelocity;
  27.  
  28.         transform.rotation = Quaternion.LookRotation(new Vector3(h, 0, v));
  29.  
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment