Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by DahFluffyNinja · Feb 26, 2020 at 07:55 AM · wall collisionwall jumpwalljump

I can not get my character to crouch? Character not sliding on walls?

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events;

public class Walls2 : MonoBehaviour {

 public float maxSpeed = 10f;
 bool facingRight = true;
 public Animator anim;
   
 //sets up the grounded stuff
 bool grounded = false;
 bool touchingWall = false;
 public Transform groundCheck;
 public Transform wallCheck;
 float groundRadius = 0.2f;
 float wallTouchRadius = 0.2f;
 public LayerMask whatIsGround;
 public LayerMask whatIsWall;
 public float jumpForce = 700f;
 public float jumpPushForce = 700f;
 bool crouch = false;
 float horizontalMove = 0f;
 //double jump
 bool doubleJump = false;
   
  

 // Use this for initialization
 void Start()
 {

     anim = GetComponent<Animator>();
 }

 // Update is called once per frame
 void FixedUpdate()
 {
     horizontalMove = Input.GetAxisRaw("Move") * maxSpeed;
     // The player is grounded if a linecast to the groundcheck position hits anything on the ground layer.
     grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
     touchingWall = Physics2D.OverlapCircle(wallCheck.position, wallTouchRadius, whatIsWall);
     anim.SetBool("Ground", grounded);

     if (grounded)
     {
         doubleJump = false;
         anim.SetBool("Up", false);
     }

     if (touchingWall)
     {
         grounded = false;
         doubleJump = false;
     }

     anim.SetFloat("speed", GetComponent<Rigidbody2D>().velocity.y);



     float move = Input.GetAxis("Move");
         anim.SetFloat("speed", Mathf.Abs(horizontalMove));
     

     anim.SetFloat("speed", Mathf.Abs(move));

     GetComponent<Rigidbody2D>().velocity = new Vector2(move * maxSpeed, GetComponent<Rigidbody2D>().velocity.y);

     // If the input is moving the player right and the player is facing left...
     if (move > 0 && !facingRight)
     {
         // ... flip the player.
         Flip();
     }// Otherwise if the input is moving the player left and the player is facing right...
     else if (move < 0 && facingRight)
     {
         // ... flip the player.
         Flip();
     }
 }
 void Update()
 {

     // If the jump button is pressed and the player is grounded then the player should jump.
     if ((grounded || !doubleJump) && Input.GetButtonDown("Up"))
     {
         anim.SetBool("Ground", false);
         anim.SetBool("Up", true);
         GetComponent<Rigidbody2D>().AddForce(new Vector2(0, jumpForce));

         if (!doubleJump && !grounded)
         {
             doubleJump = true;
         }

     }
     if (grounded && Input.GetButtonDown("Down"))
     {

         crouch = true;
         
         GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 0));
     }
     else if (Input.GetButtonUp("Down"))
     {
         crouch = false;
     }


     if (touchingWall && Input.GetButtonDown("Up"))
     {
         WallJump();
     }


     void WallJump()
     {
         GetComponent<Rigidbody2D>().AddForce(new Vector2(jumpPushForce, jumpForce));
     }

 }
     void Flip()
     {

         // Switch the way the player is labelled as facing
         facingRight = !facingRight;

         //Multiply the player's x local cale by -1
         Vector3 theScale = transform.localScale;
         theScale.x *= -1;
         transform.localScale = theScale;
     }
 

}

Comment
Add comment · Show 1
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
avatar image DahFluffyNinja · Feb 26, 2020 at 01:55 AM 0
Share

I dont know where I am going wrong would appreciate the help. I Combined two of my scripts and can not get them to work all the way.

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

196 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 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

wallrun or object magnetized to wall 1 Answer

implementing a wall jump 1 Answer

Does anyone know how to add a Wall Jump + Slide in a 2D Platformer?,Does anyone know how to add a wall jump + slide? 0 Answers

2D sidescrolling game. Jumping problems through platforms and platform effector. 0 Answers

How to move upward with wall jump and not be pulled down too quickly? 0 Answers


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