Feature: Changable Movement Keys in Editor
This commit is contained in:
parent
91e43f9b3a
commit
4e51e6d212
@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -11,8 +12,16 @@ public class Movement : MonoBehaviour
|
|||||||
public float gravity = 9.8f;
|
public float gravity = 9.8f;
|
||||||
public PickUpObject throwForce;
|
public PickUpObject throwForce;
|
||||||
|
|
||||||
private CharacterController controller;
|
public CharacterController controller;
|
||||||
private Vector3 moveDirection = Vector3.zero;
|
public Vector3 moveDirection = Vector3.zero;
|
||||||
|
|
||||||
|
[Header("Keybinds")]
|
||||||
|
public KeyCode forwardsKey = KeyCode.W;
|
||||||
|
public KeyCode backwardsKey = KeyCode.S;
|
||||||
|
public KeyCode leftKey = KeyCode.A;
|
||||||
|
public KeyCode rightKey = KeyCode.D;
|
||||||
|
public KeyCode sprintKey = KeyCode.LeftShift;
|
||||||
|
public KeyCode jumpKey = KeyCode.Space;
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
@ -21,41 +30,46 @@ public class Movement : MonoBehaviour
|
|||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
if (controller.isGrounded)
|
float forwards = Convert.ToSingle(Input.GetKey(forwardsKey));
|
||||||
|
float backwards = Convert.ToSingle(Input.GetKey(backwardsKey));
|
||||||
|
float left = Convert.ToSingle(Input.GetKey(leftKey));
|
||||||
|
float right = Convert.ToSingle(Input.GetKey(rightKey));
|
||||||
|
moveDirection = new Vector3(right - left, 0, forwards - backwards);
|
||||||
|
|
||||||
|
if (!controller.isGrounded)
|
||||||
{
|
{
|
||||||
// Change the direction the player is facing based on the direction they are moving
|
moveDirection.y -= gravity * Time.deltaTime;
|
||||||
if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
|
controller.Move(moveDirection * Time.deltaTime);
|
||||||
{
|
return;
|
||||||
Quaternion ToRotation = Quaternion.LookRotation(new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")));
|
}
|
||||||
throwForce.throwForce = 8.5f;
|
|
||||||
transform.rotation = Quaternion.RotateTowards(transform.rotation, ToRotation, turnSpeed * Time.deltaTime);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throwForce.throwForce = 4.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
|
throwForce.throwForce = 4.0f;
|
||||||
|
// Change the direction the player is facing based on the direction they are moving
|
||||||
|
if (moveDirection != Vector3.zero)
|
||||||
|
{
|
||||||
|
Quaternion ToRotation = Quaternion.LookRotation(new Vector3(right - left, 0, forwards - backwards));
|
||||||
|
throwForce.throwForce = 8.5f;
|
||||||
|
transform.rotation = Quaternion.RotateTowards(transform.rotation, ToRotation, turnSpeed * Time.deltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.GetKey(sprintKey))
|
||||||
|
{
|
||||||
|
moveDirection *= sprintSpeed;
|
||||||
|
jumpForce = 4.0f;
|
||||||
|
if(moveDirection != Vector3.zero)
|
||||||
|
{
|
||||||
|
throwForce.throwForce = 20.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
moveDirection *= speed;
|
||||||
|
jumpForce = 2.5f;
|
||||||
|
}
|
||||||
|
|
||||||
if (Input.GetKey(KeyCode.LeftShift))
|
if (Input.GetKeyDown(jumpKey))
|
||||||
{
|
{
|
||||||
moveDirection *= sprintSpeed;
|
moveDirection.y = jumpForce;
|
||||||
jumpForce = 4.0f;
|
|
||||||
if(Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
|
|
||||||
{
|
|
||||||
throwForce.throwForce = 20.0f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
moveDirection *= speed;
|
|
||||||
jumpForce = 2.5f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Input.GetButton("Jump"))
|
|
||||||
{
|
|
||||||
moveDirection.y = jumpForce;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
moveDirection.y -= gravity * Time.deltaTime;
|
moveDirection.y -= gravity * Time.deltaTime;
|
||||||
|
Loading…
Reference in New Issue
Block a user