- Home /
How to fix my movement?
My movement just randomly stopped working, I can no longer move my character. It should still work, but for some reason it doesn't. Here is the code:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;
public class MovementPlayer1 : MonoBehaviour { // Start is called before the first frame update public float speed; public float jumpForce; private float moveInput; public float WallJumpForce; public float jumpPushForce; private bool facingRigh = true; private int extraJumps; public int extraJumpValue; public float xWallForce; public float yWallForce; private Rigidbody2D rb; bool isTouchingFront; bool isTouchingBog; public Transform frontCheck; bool WallSliding; public GameObject player; public float wallSlidingSpeed; public float wallJumpTime;
public bool isGrounded;
public bool isWalledLeft;
public bool isWalledRight;
public bool canWallJump;
public bool wallJumping;
public bool canMove;
public Animator Player;
public Animator clickEOne;
public GameObject signOpenOne;
public Transform groundCheck;
public float checkRadius;
public LayerMask whatIsGround;
public LayerMask whatIsNoJuming;
public bool canInteractOne;
public bool isSignOneOpen;
void Start()
{
extraJumps = extraJumpValue;
}
// Update is called once per frame
private void FixedUpdate()
{
isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
moveInput = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
if (canMove == true)
{
}
if (facingRigh == false && moveInput > 0 && canMove == true)
{
flip();
}
else if (facingRigh == true & moveInput < 0 && canMove == true)
{
flip();
}
}
void Update()
{
if (canMove == false)
{
rb.velocity = new Vector2(0f, rb.velocity.y);
}
if (Input.GetKeyDown(KeyCode.Escape))
{
Application.Quit();
}
if (moveInput == 0)
{
Player.SetBool("isRunning", false);
}
else
{
Player.SetBool("isRunning", true);
}
if (isGrounded == true)
{
extraJumps = extraJumpValue;
Player.SetBool("isJumping", false);
}
else
{
Player.SetBool("isJumping", true);
}
if (Input.GetKeyDown(KeyCode.Space) && extraJumps > 0 && canMove == true && isTouchingBog != true)
{
rb.velocity = Vector2.up * jumpForce;
Player.SetTrigger("jumping");
extraJumps--;
}
else if (Input.GetKeyDown(KeyCode.Space) && extraJumps == 0 && isGrounded == true && canMove == true && isTouchingBog != true)
{
rb.velocity = Vector2.up * jumpForce;
Player.SetTrigger("jumping");
}
isTouchingFront = Physics2D.OverlapCircle(frontCheck.position, checkRadius, whatIsGround);
isTouchingBog = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsNoJuming);
if (isTouchingFront == true && isGrounded == false && moveInput != 0 && isTouchingBog != true)
{
WallSliding = true;
}
else
{
WallSliding = false;
}
if (WallSliding == true)
{
rb.velocity = new Vector2(rb.velocity.x, Mathf.Clamp(rb.velocity.y, -wallSlidingSpeed, float.MaxValue));
}
if (Input.GetKey(KeyCode.Space) && WallSliding == true && canWallJump == true)
{
wallJumping = true;
}
if (wallJumping == true)
{
rb.velocity = new Vector2(xWallForce * -moveInput, yWallForce);
}
if (canInteractOne == true)
{
if (Input.GetKeyDown(KeyCode.E))
{
Debug.Log("OwO sign got clicked");
Time.timeScale = 0f;
isSignOneOpen = true;
}
}
if (isSignOneOpen == true)
{
signOpenOne.SetActive(true);
Time.timeScale = 0f;
if (Input.GetMouseButtonDown(0))
{
isSignOneOpen = false;
Time.timeScale = 1f;
}
}
else
{
signOpenOne.SetActive(false);
Time.timeScale = 1f;
}
}
void SetWallJumpingToFalse()
{
wallJumping = false;
}
void flip()
{
facingRigh = !facingRigh;
Vector3 Scaler = player.transform.localScale;
Scaler.x *= -1;
player.transform.localScale = Scaler;
}
void Jump()
{
rb.AddForce(new Vector2(0f, jumpForce), ForceMode2D.Impulse);
}
void WallJumpLeft()
{
rb.AddForce(new Vector2(speed * jumpPushForce, WallJumpForce), ForceMode2D.Impulse);
}
void WallJumpRight()
{
rb.AddForce(new Vector2(speed * jumpPushForce, WallJumpForce), ForceMode2D.Impulse);
}