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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by adityapurwa · Dec 04, 2014 at 01:52 PM · raycastjumpplatformercolission

3D Jump Colission Detection

Hi,

Sorry if you think that this is a duplicate. I have been searching this site for every possible scenario for my game, but I have no luck finding it.

I am creating a 3D side scrolling bounce game. I want the user to be able to jump when they were on the ground (or hitting the ground after jumping, like the usual bounce game on your old phone).

I am using raycast to check for the colission, the pivot point of the sphere is on the center of it.

 bool IsGrounded()
 {
     RaycastHit hitInfo;
     if (Physics.Raycast(this.transform.position, Vector3.down, out hitInfo, this.transform.localScale.y / 2 - jumpTolerance))
     {
         return true;
     }          
     return false;
 }

I am using the jump tolerance because dividing the raycast with two still giving too much raycast length.

On the fixed update, I am using this code.

 if (attempToJump)
 {
     Jump();            
 }

The jump method is using the raycast checker.

 void Jump()
 {
     if (IsGrounded())
     {
         rigidbody.AddForce(0, jumpHeight, 0);
     }           
 }

The attemptToJump variable is set inside the Update() method because it is suggested to write input related code inside the Update() method, and physics related code inside FixedUpdate() method. It just check for the GetKey(KeyCode.Space) and set the attemp to true, otherwise false.

The problem is, if I hold the space bar, it jumps, when it lands, it jumps again but with higher jump range. Sometimes, it doesnt bounce when I keep pressing the space bar after it bounce naturally (Based on the physics material), or it jump lower than the desired jump height

Here is the screenshot of the simple game. alt text

Thank you

bounce3d.png (185.2 kB)
Comment
Add comment · Show 2
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 SaraCecilia · Dec 04, 2014 at 02:08 PM 0
Share

What alternatives have you tried? This thread not helping? http://forum.unity3d.com/threads/raycast-jump-repeating.39221/

avatar image adityapurwa · Dec 04, 2014 at 02:34 PM 0
Share

Thank you for the link, I havent tried that solution yet. Do you think my solution to put the attempt o jump on Update() method ins$$anonymous$$d of checking for the input inside the FixedUpdate() is a right way to do it?

I read the documentation about Relative force and Force, but I cant understand it clearly. What is the point?

Thank you

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by HellsPlumber · Jun 28, 2015 at 12:10 PM

If you don't wish to be able to hold Space to continually jump, you'll need to check for the OnDown trigger while you're grounded. For example;

 if (IsGrounded()&&Input.GetKeyDown("Space"))
 {
 rigidbody.AddForce(0, jumpHeight, 0);
 }

As for the extra height you're gaining from jumping when you land, my first guess would be to check your physics material on your colliders. If none are applied yet, try creating one and making sure that Bounce is set to 0.

If all else fails, try using a different velocity mode for your jump's AddForce. http://docs.unity3d.com/ScriptReference/ForceMode.html

VelocityChange is most often used for jumps as it applies the force while disregarding current mass and velocity. Hope this helps!

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to determine if the player can jump, without using raycasts. (2D) 1 Answer

Using RayCasting to check for floor and ceiling? 0 Answers

Why my variable istn't always used? 2 Answers

Raycast always hit 1 Answer

Cant jump while running left or right c#? 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