Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Player : MonoBehaviour
- {
- [SerializeField] float _speedMove, _speedRotation;
- private float _moveFoward, _moveRotation;
- private Rigidbody _rigidbody;
- // Start is called before the first frame update
- void Start()
- {
- _rigidbody = GetComponent<Rigidbody>();
- }
- // Update is called once per frame
- void Update()
- {
- _moveFoward = Input.GetAxis("Vertical");
- _moveRotation = Input.GetAxis("Horizontal");
- }
- void FixedUpdate()
- {
- Move();
- Turn();
- }
- void Move()
- {
- Vector3 movement = transform.forward * _moveFoward * _speedMove * Time.deltaTime;
- _rigidbody.MovePosition(_rigidbody.position + movement);
- }
- void Turn()
- {
- float turn = _moveRotation * _speedRotation * Time.deltaTime;
- Quaternion turnRotation = Quaternion.Euler(0f, turn, 0f);
- _rigidbody.MoveRotation(_rigidbody.rotation * turnRotation);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement