Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlayerNetworkMove : MonoBehaviour {
- Transform trans; // Used to cache the transform
- Rigidbody body; // Used to cache the RigidBody
- float hInput;
- float vInput;
- float rotationSpeed = 90f;
- void Awake()
- {
- trans = transform;
- body = GetComponent<Rigidbody>();
- }
- // Update is called once per frame
- void Update () {
- hInput = Input.GetAxis("Horizontal");
- vInput = Input.GetAxis("Vertical");
- }
- void FixedUpdate()
- {
- // Remove unwanted forces resulting from collisions
- body.velocity = Vector3.zero;
- body.angularVelocity = Vector3.zero;
- // Handle rotation
- var rot = body.rotation.eulerAngles;
- rot.y += hInput * rotationSpeed * Time.deltaTime;
- body.MoveRotation(Quaternion.Euler(rot));
- // Handle forward movement
- body.MovePosition(body.position + vInput * trans.forward * 5f * Time.deltaTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement