Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TestRigid : MonoBehaviour
  6. {
  7.     public float Speed = 5f;
  8.     public float JumpHeight = 2f;
  9.     public float GroundDistance = 0.2f;
  10.     public float DashDistance = 5f;
  11.     public LayerMask Ground;
  12.  
  13.     private Rigidbody _body;
  14.     private Vector3 _inputs = Vector3.zero;
  15.     private bool _isGrounded = true;
  16.     private Transform _groundChecker;
  17.  
  18.     // Start is called before the first frame update
  19.     void Start()
  20.     {
  21.         _body = GetComponent<Rigidbody>();
  22.         _groundChecker = transform.GetChild(0);
  23.  
  24.     }
  25.  
  26.     // Update is called once per frame
  27.     void Update()
  28.     {
  29.         _isGrounded = Physics.CheckSphere(_groundChecker.position, GroundDistance, Ground, QueryTriggerInteraction.Ignore);
  30.  
  31.         _inputs = Vector3.zero;
  32.         _inputs.x = Input.GetAxis("Horizontal_p1");
  33.         _inputs.z = Input.GetAxis("Vertical_p1");
  34.         if (_inputs != Vector3.zero)
  35.             transform.forward = _inputs;
  36.  
  37.     }
  38.  
  39.     void FixedUpdate()
  40.     {
  41.         _body.MovePosition(_body.position + _inputs * Speed * Time.fixedDeltaTime);
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement