Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SubzoneGames · Jan 08, 2021 at 10:15 PM · 2d-platformermovement script

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);
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

124 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make my 2D movement smooth 1 Answer

Is there a way to make a Rigidbody2D Ignore the TimeScale? 0 Answers

Unity 2D Movement Script 3 Answers

How do I stop momentum in 2D sidescroller? 1 Answer

Why does this script crash Unity? Also simple random 2D movement? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges