-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerMotor
48 lines (43 loc) · 1.37 KB
/
PlayerMotor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMotor : MonoBehavior
{
private CharacterController controller;
private Vector3 playerVelocity;
private bool isGrounded;
public float speed = 5f;
public float gravity = -9.8f;
public float JumpHeight = 3f;
// Start is called before the first frame update
void Start()
{
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
isGrounded = controller.isGrounded;
}
//receive the inputs for our InputManager.cs and apply them to our character controller.
public void ProcessMove(Vector2 input)
{
Vector3 moveDirection = Vector3.zero;
moveDirection.x = input.x;
moveDirection.z = input.y;
controller.Move(transform.TransformDirection(moveDirection) * speed * Time.deltaTime);
playerVelocity.y += gravity * Time.deltaTime;
if(isGrounded && playerVelocity.y < 0)
playerVelocity.y = -2f;
controller.Move(playerVelocity * Time.deltaTime);
Debug.Log(playerVelocity.y);
}
}
void Jump()
//public
{
if (isGrounded)
{
playerVelocity.y = MathF.Sqrt(jumpHeight * -3.0f * gravity);
}
}