2024-04-28 14:13:37 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class Movement : MonoBehaviour
|
|
|
|
{
|
|
|
|
public float speed = 5.0f;
|
2024-04-28 17:14:08 +01:00
|
|
|
public float turnSpeed;
|
2024-04-28 14:13:37 +01:00
|
|
|
public float sprintSpeed = 10.0f;
|
2024-04-28 15:08:27 +01:00
|
|
|
public float jumpForce;
|
2024-04-28 14:13:37 +01:00
|
|
|
public float gravity = 9.8f;
|
2024-04-28 17:14:08 +01:00
|
|
|
public PickUpObject throwForce;
|
2024-04-28 14:13:37 +01:00
|
|
|
|
|
|
|
private CharacterController controller;
|
|
|
|
private Vector3 moveDirection = Vector3.zero;
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
controller = GetComponent<CharacterController>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
if (controller.isGrounded)
|
|
|
|
{
|
2024-04-28 17:14:08 +01:00
|
|
|
// Change the direction the player is facing based on the direction they are moving
|
|
|
|
if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
|
|
|
|
{
|
|
|
|
Quaternion ToRotation = Quaternion.LookRotation(new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")));
|
2024-04-28 17:20:37 +01:00
|
|
|
throwForce.throwForce = 8.5f;
|
2024-04-28 17:14:08 +01:00
|
|
|
transform.rotation = Quaternion.RotateTowards(transform.rotation, ToRotation, turnSpeed * Time.deltaTime);
|
|
|
|
}
|
2024-04-28 17:20:37 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
throwForce.throwForce = 4.0f;
|
|
|
|
}
|
2024-04-28 17:14:08 +01:00
|
|
|
|
|
|
|
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
|
2024-04-28 14:13:37 +01:00
|
|
|
|
|
|
|
if (Input.GetKey(KeyCode.LeftShift))
|
|
|
|
{
|
|
|
|
moveDirection *= sprintSpeed;
|
2024-04-28 15:08:27 +01:00
|
|
|
jumpForce = 4.0f;
|
2024-04-28 17:14:08 +01:00
|
|
|
if(Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
|
|
|
|
{
|
|
|
|
throwForce.throwForce = 20.0f;
|
|
|
|
}
|
2024-04-28 14:13:37 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
moveDirection *= speed;
|
2024-04-28 15:08:27 +01:00
|
|
|
jumpForce = 2.5f;
|
2024-04-28 14:13:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Input.GetButton("Jump"))
|
|
|
|
{
|
|
|
|
moveDirection.y = jumpForce;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
moveDirection.y -= gravity * Time.deltaTime;
|
|
|
|
controller.Move(moveDirection * Time.deltaTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|