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
0
Question by AviKohl3D · May 14, 2015 at 03:54 PM · inputjumpingcrouching

Trying to script "Beyond Oasis"-style crouch and jump

Beyond Oasis is a genesis-era game with input features I'm trying to emulate.

The objective here is to make the player jump if the crouch button is tapped (the first few frames of the crouch animation would be played before transitioning into the jump). If the crouch button is held, the player stays in the crouch and goes straight back into idle when the button is released.

This is the (dysfunctional) code I have so far:

 float timepass = 0.0f;
 float timelimit = 0.25f;
 
 if (Input.GetButtonDown ("Duck")) {
     anim.SetBool ("Duck", true);
     if (Input.GetButton ("Duck")){
         timepass += Time.fixedDeltaTime;
     }
 }
 if (Input.GetButtonUp ("Duck")) {
     if(timepass < timelimit){
         anim.SetTrigger ("Jump");
     }
      anim.SetBool ("Duck",false);
      float timepass = 0.0f;
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by FortisVenaliter · May 14, 2015 at 04:06 PM

Your Input.GetButton call, which checks if a button is held down, is inside the check for if a button is pressed this frame. Which means that timepass will only be incremented the first frame of the button press.

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 AviKohl3D · May 15, 2015 at 05:25 AM 0
Share

This is the closest to success I've come so far. Lingering problems:

  1. The time detection feature is totally unreliable. No matter how low I set timelimit, jump is never triggered until I hold down the input for at least a full second. Sometimes I can keep the input held for several seconds and the trigger registers upon release -or sometimes before. Basically, the jump seems to get triggered at random but just tapping never sets it off. Aside from the randomness, this is THE OPPOSITE of what I'm trying to do.

  2. When the jump trigger DOES register, the jump animation often (but not always) plays twice. Guess that's an extension of the first problem.

float timepass = 0.0f; float timelimit = 0.1f;

if (Input.GetButton ("Duck")) {

  anim.SetBool ("Duck", true);
  timepass += Time.deltaTime;

}

if (Input.GetButtonUp ("Duck")) {

  if (timepass < timelimit){
       anim.SetTrigger ("Jump");
  }
  timepass = 0.0f;
  anim.SetBool ("Duck", false);

}

avatar image
0

Answer by AviKohl3D · May 15, 2015 at 05:26 AM

I just achieved the effect I wanted via simple input scripts and animation states. Just need to tweak the anim clips to make it seamless.

The danger of needlessly over-complicating things never goes away.

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

2 People are following this question.

avatar image avatar image

Related Questions

Input Axis Vertical is not set up? 1 Answer

Playerobject makes weird "jump" 1 Answer

(New input system) How to queue a jump before you touch the ground? 0 Answers

How to make first person movement with keyboard, on new input system 1 Answer

3D coyote time 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