Compare commits
No commits in common. "97ee01f5dff967c10f481cb7371a1a9384578bd9" and "5fd403626e9664c9fb6c4459070f53a796cda405" have entirely different histories.
97ee01f5df
...
5fd403626e
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"version": "1.0",
|
||||
"components": [
|
||||
"Microsoft.VisualStudio.Workload.ManagedGame"
|
||||
]
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class Character : MonoBehaviour
|
||||
{
|
||||
[Header("Movement")]
|
||||
public float moveSpeed = 2f;
|
||||
public float groundDrag = 1f;
|
||||
|
||||
private float horizontalInput, verticalInput;
|
||||
private Vector3 moveDirection;
|
||||
private Rigidbody rb;
|
||||
|
||||
public float speed = 2f;
|
||||
|
||||
[Header("Keybindings")]
|
||||
public KeyCode jumpKey = KeyCode.Space;
|
||||
|
||||
public float jumpForce;
|
||||
public float jumpCooldown;
|
||||
bool readyToJump = true;
|
||||
|
||||
[Header("Groud Check")]
|
||||
public float playerHeight;
|
||||
public LayerMask whatIsGround;
|
||||
public bool grounded;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
rb = gameObject.GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f, whatIsGround);
|
||||
|
||||
MyInput();
|
||||
SpeedControl();
|
||||
|
||||
if(grounded)
|
||||
{
|
||||
rb.drag = groundDrag;
|
||||
}
|
||||
else
|
||||
{
|
||||
rb.drag = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
MovePlayer();
|
||||
}
|
||||
|
||||
private void MyInput()
|
||||
{
|
||||
horizontalInput = Input.GetAxisRaw("Horizontal");
|
||||
verticalInput = Input.GetAxisRaw("Vertical");
|
||||
|
||||
|
||||
if(Input.GetKey(jumpKey) && readyToJump && grounded)
|
||||
{
|
||||
readyToJump = false;
|
||||
|
||||
Jump();
|
||||
|
||||
Invoke(nameof(ResetJump), jumpCooldown);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void MovePlayer()
|
||||
{
|
||||
moveDirection = new Vector3(0, 0, verticalInput) + new Vector3(horizontalInput, 0, 0);
|
||||
|
||||
rb.AddForce(moveDirection.normalized * moveSpeed * 10f, ForceMode.Force);
|
||||
}
|
||||
|
||||
private void SpeedControl()
|
||||
{
|
||||
Vector3 flatVel = new Vector3(rb.velocity.x, 0f, rb.velocity.z);
|
||||
|
||||
if(flatVel.magnitude > moveSpeed)
|
||||
{
|
||||
Vector3 limitedVel = flatVel.normalized * moveSpeed;
|
||||
rb.velocity = new Vector3(limitedVel.x, rb.velocity.y, limitedVel.z);
|
||||
}
|
||||
}
|
||||
|
||||
private void Jump()
|
||||
{
|
||||
rb.velocity = new Vector3(rb.velocity.x, 0f, rb.velocity.z);
|
||||
|
||||
rb.AddForce(transform.up * jumpForce, ForceMode.Impulse);
|
||||
}
|
||||
|
||||
private void ResetJump()
|
||||
{
|
||||
readyToJump = true;
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 41df0369bf5d3b64cb9c32c46f2fe9f0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,7 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e4d3f8ed1d2c8414bbe1aa51abfdb3bc
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Before Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 6.8 KiB |
Before Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 4.8 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 7.4 KiB |
Before Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 7.7 KiB |
Before Width: | Height: | Size: 7.0 KiB |
Before Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 7.5 KiB |
Before Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 6.2 KiB |
Before Width: | Height: | Size: 9.3 KiB |
Before Width: | Height: | Size: 15 KiB |