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
1
Question by panxter · Jan 28, 2013 at 11:07 AM · rigidbodyjump

Jump angle relative to surface?

Hey men and gentleladies! I'm rather new to Unity, but I'm learning fast. I'm trying to make a jump script that makes the rigidbody 'player' jump in an angle relative to the surface it's placed on. I.E. if you're standing on a 45degree angled surface, the player doesnt jump straight up, but jumps out in a 45degree angle, 90degrees on the surface. I'm using C# for all my scripts, but I have no clue on how to make this. There's no constant 'up' direction of my player, since its a rolling sphere, so I can't use that, unfortunately. Anyone have an idea of how I can solve this in a good way? :) Thanks in advance

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
1
Best Answer

Answer by Berenger · Jan 28, 2013 at 11:11 AM

Hi !

So, you need the normal of the ground you're rolling on. As you're using a rigidbody, you can use the function OnCollisionStay, which gives you access to the contact points and the normal.

I'm not explaining everything, partly to keep a bit of mistery, but mostly because I think people learn better when they have to search a bit, once on the right path.

Good luck :)

Comment
Add comment · 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 panxter · Jan 28, 2013 at 11:14 AM 0
Share

Hey Berenger, thank you very much for the answer, this surely got me on the right track :) I appreciate you not giving it all away, as I prefer to learn as I go!

avatar image Dracalis · Feb 19, 2015 at 11:27 AM 0
Share

I'm trying to implement the same feature through JavaScript. I've got a rolling ball that I'd like to make push off whatever surface it's touching when the "Jump" button is hit, rather than just moving straight upwards. I'm a novice at this, and scripting isn't my forté; I could use some more hand-holding on this.

 #pragma strict
 
 var jumpHeight = 8;
 var distToGround : float;
 
 // Adds upwards velocity to the ball when "Jump" is hit
 function Update (){
     if (Input.GetButtonDown("Jump") && IsGrounded ()){
         rigidbody.velocity.y = jumpHeight;
     }
 }
 
 // Checks whether or not the ball is on the ground
 // This only works vertically — steep slopes won't trigger it
 function IsGrounded () : boolean{
     return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1);
 }

That's what I've got thus far. It only makes the ball move up, and won't even work if the slope is too steep. I'm not sure how to improve upon it. While hints are good for some people, I'm still stumped; I don't know coding very well at all, but have been learning a lot from examples. If someone could show how I could use OnCollisionStay to get the normals and make this work, I'd very much appreciate 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

11 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

Related Questions

Jump Input Sensitivity 0 Answers

How do I make my character jump over a cube with rigid body moving towards it 1 Answer

rigidbody.AddForce jump, different heights each time 1 Answer

my jump every 3 seconds program is not working 3 Answers

Setting Rigidbody Velocity for Jump Unity 5 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