Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- //player movement using the physics engine from Ferrone Learning Unity book
- public class PlayerBehaviour : MonoBehaviour
- {
- public float moveSpeed = 10;
- public float rotateSpeed = 75;
- private float horizontalInput;
- private float verticalInput;
- private Rigidbody playerRB;
- void Start()
- {
- playerRB = GetComponent<Rigidbody>();
- }
- void Update() {
- PlayerMovement();
- }
- private void PlayerMovement() {
- verticalInput = Input.GetAxis("Vertical") * moveSpeed;
- horizontalInput = Input.GetAxis("Horizontal") * rotateSpeed;
- /* transform.Translate(Vector3.forward * verticalInput * Time.deltaTime);
- transform.Rotate(Vector3.up * horizontalInput * Time.deltaTime);*/
- }
- private void FixedUpdate() {
- Vector3 rotation = Vector3.up * horizontalInput;
- Quaternion angleRot = Quaternion.Euler(rotation * Time.fixedDeltaTime);
- playerRB.MovePosition(transform.position + transform.forward * verticalInput * Time.fixedDeltaTime);
- playerRB.MoveRotation(playerRB.rotation * angleRot);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement