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 rasheedqw · Jul 15, 2013 at 12:39 PM · collisionjumpingnew

can stop character form double jumping

can't get character to only jump once new to scripting the point of the script was for him to jump then reset jump to 0 so he couldn't jump twice in the air but it only resets one time the character has rigidbody on with continuous dynamic and a capsule Collider and the ground has a terrain collider i just cant get the script to tell when he in the air reset jump to 0. i ran a debug log it tells everytime he hits gound it just wont detect when he in the air been up hour trying to figure it out

please help

public var jump:float=0;

public var jumpheight :float=20;

function Update ()

{ if (Input.GetKeyDown (KeyCode.Space)) {transform.Translate(Vector3.up (jump) Time.deltaTime, Space.World);}}

function OnCollisionStay(collision : Collision){

 if (( collision.gameObject.tag==("Ground") ))
                {(jump)=(jumpheight);}

   

 else {(jump)=(jump);}
Comment
Add comment · Show 4
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 amphoterik · Jul 15, 2013 at 12:51 PM 1
Share

Please format your code correctly. It will make helping you much easier.

avatar image PAEvenson · Jul 15, 2013 at 01:57 PM 0
Share

Either use:

 Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.Space)

or write some code that waits before he jumps again. Basically what is happening is multiple update calls are occurring before your OnCollisionStay is changing your jump var.

avatar image rasheedqw · Jul 15, 2013 at 04:24 PM 0
Share

thanks just started learning 2 days ago didnt know what was going on

avatar image Beennn · Jul 15, 2013 at 06:04 PM 0
Share

Rather than checking if the players collider is touching the floor, I would use a raycast to check the height of the floor before the player jumps, then each time the player tries to jump, check to make sure their current height isn't greater than the initial jumping height.

An example of how of I mean (second example): http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by rasheedqw · Aug 05, 2013 at 02:33 AM

https://www.youtube.com/watch?v=y0tAImhbjIQ

the answer to how to stop a character from double jumping in the air is here

Comment
Add comment · Show 1 · 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 TeraTech · Feb 01, 2016 at 05:55 AM 2
Share

What if that link is lost or disabled in the future? Posting links without answers is not helpful. At the very least you could have given us the time index of the answer as the video is 38 $$anonymous$$utes long.

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

19 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

Related Questions

Multiple Cars not working 1 Answer

This is a sloppy conversion from javascript to C#, I cannot seem to get it working... 2 Answers

Don't restart music on death 2 Answers

Changing terrain texture on contact (collision) 2 Answers

Can't detect isgrounded? Help 1 Answer


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