Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlayerWorldAxisControl : MonoBehaviour
- {
- Rigidbody rb;
- public float moveSpeed = 5;
- // Use this for initialization
- void Start()
- {
- rb = GetComponent<Rigidbody>();
- }
- // Update is called once per frame
- void Update()
- {
- float h = Input.GetAxis("Horizontal");
- float v = Input.GetAxis("Vertical");
- float fallSpeed = rb.velocity.y;
- Vector3 newVelocity = new Vector3(h, 0, v) * moveSpeed;
- newVelocity.y = fallSpeed;
- rb.velocity = newVelocity;
- transform.rotation = Quaternion.LookRotation(new Vector3(h, 0, v));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment