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 Sharpytwo · Jul 19, 2012 at 02:14 PM · collisionmovementtriggerjump

My movement function with jump won't work with collider function

this is for a sidescrolling platformer, I have a ground (a box) and sticking out on top of this is a trigger. the character is a rigidbody cube with applying forces for movement. whenever the character enters the trigger (whenever it touches the ground) i want the character to be able to jump, meaning that when the character is in the air i want to disable the jump function. i got the trigger working and i got a variable saying if it was grounded or not, but when i try to use that variable in the jump part the it seems like that part of the script stops working. so it doesnt react.

var jumpForce = 200; private var onGround = false;

function FixedUpdate() { if(Input.GetKey(KeyCode.UpArrow) && onGround) { rigidbody.AddForce(0,jumpForce * 1,0); } }

function OnTriggerEnter(character : Collider) { var onGround = true; print(onGround); } function OnTriggerExit(character : Collider) { var onGround = false; print (onGround); }

This is the part of the code that SHOULD handle jumping... I cannot for the life of me find a solution to this... i have looked at every forumpost and question i can find... it's probably a simple solution but I'm very fresh to programming so some help please? :)

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 Sharpytwo · Jul 19, 2012 at 05:36 PM 0
Share

well, it works now, no idea how it was fixed, but if someone comes upon the same problem just ask and ill post the code :)

1 Reply

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

Answer by ScroodgeM · Jul 19, 2012 at 06:51 PM

may be you should not declare new values inside methods? e.g. remove 'var' before 'onGround'?

function OnTriggerEnter(character : Collider)
{
  onGround = true;
  print(onGround);
}
function OnTriggerExit(character : Collider)
{
  onGround = false;
  print (onGround);
}
Comment
Add comment · Show 11 · 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 Sharpytwo · Jul 20, 2012 at 12:33 PM 0
Share

that worked, thanks :) kinda noobish error i guess, but a beginner has to learn! :)

avatar image ScroodgeM · Jul 20, 2012 at 12:36 PM 0
Share

everybody was a beginner 8) it's O$$anonymous$$ 8)

avatar image Sharpytwo · Jul 20, 2012 at 12:57 PM 0
Share

btw, i have another small problem with the colliders... how do i script a difference between them? because as it is now all triggers trigger the same event, i tried scripting a finish line (a separate trigger with a separate script, that only contained a OnTriggerEnter and an Application.LoadLevel but it still triggered all the other stuff, and the script for that one didnt even run, strange enough. im guessing it has to do with layers or something in that area, but i cant find any documentation handling several triggers. thanks for your help btw :) edit: basically i need help to make trigger A trigger event X, whilst trigger B triggers event Y

avatar image ScroodgeM · Jul 20, 2012 at 04:16 PM 0
Share

one of solutions is to use tags - you can tag an object that must raise the event and check for this tag in OnTriggerEnter method

avatar image Sharpytwo · Jul 20, 2012 at 04:19 PM 0
Share

yeah, but will that work for instance if the player enters one trigger, he can jump, and if he enters another he can open a door? because the only thing i managed to do with this was filter what colliders would trigger, not what each trigger did.

Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Trigger respawn after collision? 3 Answers

how to make triger fireball not to pass through spesific objects 2 Answers

Multiple Colliders malfunctioning 0 Answers

How having correct bounce on a rotating pinwheel(it's more complicated)? 0 Answers

How can I make a physics object jump a given height on collision regardless of current velocity? 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