Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 /
avatar image
0
Question by Maco21 · Nov 13, 2014 at 09:27 PM · rigidbodyjumptranslatewalldiagonal

Diagonal Wall Jump

Hey everyone! I want my player jumps automatically and diagonally when I click the spacebar I'm going crazy to figure out how to do it and as the last option I decided to ask for help here, i hope you can help me T_T my player has rigidbody so i tried with addforce... i tried with transform.translate too but it's like i need to press the spacebar without interruption to get the diagonal movement, instead i need that the player does this jump with only a tap...

alt text

immagine.png (2.9 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by blueLED · Nov 13, 2014 at 09:35 PM

First, zero out your player's y velocity when he hits the wall (makes things more accurate):

 rigidbody.velocity = new Vector3(rigidbody.velocity.x, 0, rigidbody.velocity.z);

Then apply the wall jump force:

 rigidbody.AddForce(Vector3.up * wallJumpForce, ForceMode.VelocityChange);


Comment
Add comment · Show 6 · Share
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 Maco21 · Nov 14, 2014 at 12:56 PM 0
Share

hi, thanks for the reply! i forgot to say that it is a 2D game some of the code works greatly: when i press the spacebar it moves automatically and when it hit the wall it stops moving... but there are some problems.. there's no VelocityChange in Force$$anonymous$$ode2D and it doesn't go diagonally but only upwards, so i changed Vector3.up in Vector2.right but it doesn't go diagonally ... with what can i replace the Force$$anonymous$$ode.VelocityChange and how can i get it to move diagonally? another question.. now the rigidbody velocity of the player when it's colliding with the wall is 0, so how can i get the player to move again(while it is colliding with the wall) in the other direction and diagonally when i press the spacebar again? i'm sorry for all these questions and my terrible english D: this is what i wrote:

     public int wallJumpForce = 10;
 
     void Update (){
         if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.W)) {
             rigidbody2D.AddForce(Vector2.right * wallJumpForce, Force$$anonymous$$ode2D.Impulse); // i tried for no reason Impulse;        
         }
 
     }
     
     
     void OnCollisionEnter2D (Collision2D other) {
         if (other.gameObject.tag == "wall"){
             rigidbody2D.velocity = new Vector3(rigidbody2D.velocity.x, 0, 0);
         }
     
     }

avatar image Immanuel-Scholz · Nov 14, 2014 at 01:16 PM 0
Share
 rigidbody2D.velocity = new Vector2(-rigidbody2D.velocity.x, rigidbody2D.velocity.y);
avatar image blueLED · Nov 14, 2014 at 09:47 PM 0
Share

That code was based on a 3D platformer I made. So I'm not sure about 2D. First I made wall-sliding work. Then I did the wall-jumping. I used raycasts to check what side the wall was on, the left or right. Based on that raycast, I would also apply an extra force to propel the player away from the wall. The combined forces made it go diagonal.

Start by adding a force randomly so you can see that it works. Then get the raycasting to work so you know which side to apply the force.

avatar image Maco21 · Nov 14, 2014 at 10:10 PM 0
Share

thanks for the help again anyway i've solved most of the problems.. the only problem i still have is get it to go diagonally how can i say to unity to go upwards and right(or left) to get the diagonal movement with only one press? o.O

i solved it!! anyway thanks blueLed for having tried to help me

avatar image adityag5 Maco21 · Jan 22, 2021 at 07:37 PM 0
Share

How did you solve it?

avatar image adityag5 · Jan 22, 2021 at 09:30 PM 0
Share

How did u solve it?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make sure that my cube can only jump when in contact with the ground 2 Answers

Preventing Rotated Jumping (C#) 1 Answer

HELP! stuck on wall jump Unity 2D 1 Answer

Jump and Hold on!! 0 Answers

Trying to create a jump script without velocity 3 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