• 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
Question by Nony42 · Sep 22, 2013 at 05:12 PM · jumpwallwall jump

Jumping away from a wall

I am trying to make a 2D platformer and I want the player to jump away from the wall when he does a wall jump. I recall during an FPS tutorial I did that there was some API function that allowed you to find the angle perpendicular to the surface you had collided with.

For instance, if you were to shoot the ground from any angle, it knew to animate the spark straight up away from the ground. Also, if you shot the wall, it knew to animate sideways away from the wall.

That FPS tutorial is not longer there so I'm not sure if that was one of the outdated functions. Any help will be greatly appreciated. I am using the character controller.

if (controller.collisionFlags == CollisionFlags.Sides) //if touching walls only

{

moveDirection.x = //away from the wall;

moveDirection.y = wallJumpSpeed;

}

Comment

People who like this

0 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 Nony42 · Sep 24, 2013 at 06:46 AM 0
Share

Does anyone know if I could use Vector3.Reflect() or Quaternion.FromToRotation()? Or maybe I could check to see if one side is free and then jump towards that direction?

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by Tyrrrz · Sep 28, 2013 at 08:55 PM

You can use character controller's OnControlColliderHit event and analyze the ControllerCollidrHit argument which has a "normal" property which returns collision normal vector and "moveDirection" which returns the moving direction in the moment of collision. Then you can use movement = Vector3.Reflect(moveDirection, normal); and also add some vertical speed to keep afloat for chain wall jymps movement.y += jumpOffHeight;

Comment

People who like this

0 Show 2 · 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 Nony42 · Sep 30, 2013 at 12:35 AM 0
Share

Doesn't Vector3.Reflect() require continuous movement? I was wanting a brief cling when the player hit the wall.

Also, once I learned about the physics limitations of the character controller I decided to use a rigid body controller. This is what I've been able to find to achieve what I wanted.

     void OnCollisionStay(Contacts contact)
     {
       if(Vector3.Angle(contact[0].normal, Vector3.Right) == 180)
       {
          //right wall
       }
       else if (Vector3.Angle(contact[0].normal, Vector3.Left == 180)
       {
         //left wall
       }
     }

Let me know if you know of any better way of doing this.

avatar image MelissaFPG · Apr 26, 2014 at 02:24 PM 0
Share

Small correction: it's the OnControllerColliderHit event. (Controller instead of Control).

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Jumping away from the wall 0 Answers

Making a character jump with the Character Controller Component instead of Capsule Collider 0 Answers

3d wall jumping with charter controller 1 Answer

HELP! stuck on wall jump Unity 2D 1 Answer

Jump and Hold on!! 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