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 TestRigid : MonoBehaviour
- {
- public float Speed = 5f;
- public float JumpHeight = 2f;
- public float GroundDistance = 0.2f;
- public float DashDistance = 5f;
- public LayerMask Ground;
- private Rigidbody _body;
- private Vector3 _inputs = Vector3.zero;
- private bool _isGrounded = true;
- private Transform _groundChecker;
- // Start is called before the first frame update
- void Start()
- {
- _body = GetComponent<Rigidbody>();
- _groundChecker = transform.GetChild(0);
- }
- // Update is called once per frame
- void Update()
- {
- _isGrounded = Physics.CheckSphere(_groundChecker.position, GroundDistance, Ground, QueryTriggerInteraction.Ignore);
- _inputs = Vector3.zero;
- _inputs.x = Input.GetAxis("Horizontal_p1");
- _inputs.z = Input.GetAxis("Vertical_p1");
- if (_inputs != Vector3.zero)
- transform.forward = _inputs;
- }
- void FixedUpdate()
- {
- _body.MovePosition(_body.position + _inputs * Speed * Time.fixedDeltaTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement