mirror of
https://github.com/zoriya/Prototype-Magnifique.git
synced 2026-05-30 09:19:09 +00:00
Changing player movements
This commit is contained in:
@@ -5,12 +5,18 @@ public class PlayerMovement : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private int speed = 10;
|
||||
[SerializeField] private int airSpeed = 5;
|
||||
[SerializeField] private int jumpForce = 400;
|
||||
[SerializeField] private int jumpForce = 8;
|
||||
[SerializeField] private int smallJump = 4;
|
||||
[SerializeField] private float gravity = 8.5f;
|
||||
|
||||
[Space]
|
||||
[SerializeField] private LayerMask groundMask;
|
||||
[SerializeField] private LayerMask wallMask;
|
||||
|
||||
private float jumpDelay = 0;
|
||||
private bool isGrounded = true;
|
||||
private bool airControl = false;
|
||||
private bool canWallJump = false;
|
||||
private float jumpDirection;
|
||||
private bool airControl = false;
|
||||
|
||||
private Rigidbody rb;
|
||||
|
||||
@@ -20,8 +26,19 @@ public class PlayerMovement : MonoBehaviour
|
||||
rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
private void Update ()
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (Physics.OverlapSphere(rb.position, 1.5f, groundMask).Length > 0)
|
||||
isGrounded = true;
|
||||
else
|
||||
isGrounded = false;
|
||||
|
||||
if (Physics.OverlapSphere(rb.position, 1, wallMask).Length > 0)
|
||||
canWallJump = true;
|
||||
else
|
||||
canWallJump = false;
|
||||
|
||||
|
||||
if (!isGrounded)
|
||||
{
|
||||
if (jumpDirection > 0)
|
||||
@@ -40,32 +57,25 @@ public class PlayerMovement : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
rb.MovePosition(rb.position + new Vector3(Input.GetAxis("Horizontal"), 0, 0) * (airControl ? airSpeed : speed) * Time.deltaTime);
|
||||
|
||||
if(jumpDelay == 0)
|
||||
{
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(rb.position, Vector3.down, out hit, 1))
|
||||
{
|
||||
if(hit.collider.tag != "Player" || hit.collider.tag != "Projectile")
|
||||
isGrounded = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
jumpDelay--;
|
||||
}
|
||||
rb.MovePosition(rb.position + new Vector3(Input.GetAxis("Horizontal"), 0, 0) * (airControl ? airSpeed : speed) * Time.fixedDeltaTime);
|
||||
airControl = false;
|
||||
|
||||
|
||||
if (Input.GetAxis("Jump") > 0 && isGrounded)
|
||||
if (Input.GetButtonDown("Jump") && isGrounded)
|
||||
{
|
||||
print(Input.GetAxis("Jump"));
|
||||
jumpDirection = Input.GetAxis("Horizontal");
|
||||
isGrounded = false;
|
||||
jumpDelay = Mathf.Round(750 * Time.deltaTime);
|
||||
rb.AddForce(new Vector3(0, jumpForce * Input.GetAxis("Jump"), 0), ForceMode.Acceleration);
|
||||
rb.velocity = new Vector3(0, jumpForce, 0);
|
||||
}
|
||||
if(Input.GetButtonUp("Jump") && !isGrounded && rb.velocity.y > smallJump)
|
||||
{
|
||||
rb.velocity = new Vector3(0, smallJump, 0);
|
||||
}
|
||||
|
||||
airControl = false;
|
||||
}
|
||||
|
||||
if (rb.velocity.y < 1)
|
||||
{
|
||||
rb.velocity = new Vector3(0, rb.velocity.y - gravity * Time.fixedDeltaTime, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user