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 AlejandroGorgal · Oct 17, 2014 at 05:23 AM · c#animationcollidertrigger

C#: Climb ledge while inside collider

Ok so Im trying to do the following: 1-You reach a ledge. 2-Press the jump button. 3-The character climbs up.

I got this sorta working. Basically I have a collider on the ground and when you step on it plays the "climb up" animation.

Here's the code Im using to trigger this:

 // Create a reference to the animator component
     private Animator animator;
     
     
     void Start ()
     {
         // initialise the reference to the animator component
         animator = GetComponent<Animator>();
     }
     
     // check for colliders with a Trigger collider
     // if we are entering something called JumpTrigger, set a bool parameter called JumpDown to true..
     void OnTriggerEnter(Collider col)
     {
         if(col.gameObject.name == "ClimbHIGHTrigger")
         {
             animator.SetBool("ClimbHIGH", true);    
         }
     }
     
     // ..and when leaving the trigger, reset it to false
     void OnTriggerExit(Collider col)
     {
         if(col.gameObject.name == "ClimbHIGHTrigger")
         {
             animator.SetBool("ClimbHIGH", false);
         }
     }

This currently works, but it has two problems:

1-It plays the climb up animation automatically when you enter the collider, and I only want it to play when you pres the jump key.

2-It will play the animation in whatever direction you are looking at rather than the wall.

To try and solve issue #1 I tried the following:

 if(col.gameObject.name == "ClimbHIGHTrigger" && Input.GetButtonDown ("Jump"))

Sadly, while the code itself compiles without errors nothing happens when I enter the collider and press jump.

I reckon that issue #2 is probably more complex to tackle, but some pointers in fixing #1 would be a great help.

Comment
Add comment · 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 Habitablaba · Oct 17, 2014 at 07:11 AM 2
Share

What method is that if check in? It should be in OnTriggerStay()

1 Reply

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

Answer by HarshadK · Oct 17, 2014 at 07:22 AM

In line with what @Habitablaba said, you need to use OnTriggerStay while you are checking for if the player pressed jump key while in the trigger because the OnTriggerEnter will be executed only once when the player enters the trigger so if player does not press the jump key while that is executed then it will not climb, ever. So you should use OnTriggerStay().

Something like:

 void OnTriggerStay(collider col)
 {
     if(col.gameObject.name == "ClimbHIGHTrigger" && Input.GetButtonDown ("Jump"))
     {
         // Perform climb 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 AlejandroGorgal · Oct 17, 2014 at 07:37 AM 0
Share

That worked, thanks!

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

29 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Trigger transition to another animation. 2 Answers

How do I make the enemy ai animations play after the player exit the on trigger collider on the enemy ai 0 Answers

OnTriggerEnter Not Working 1 Answer

How to trigger animation on a different object? 1 Answer

Triggering animation on click when a key is collected 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