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 lNeves · Oct 01, 2014 at 02:05 AM · c#2derrorcollider

Dying Script error

I'm trying to make a game like the classic Frogger. But I having a problem with the dying script, In my script I put a void that is something like this:

 void OnTriggerEnter2D (Collider2D other){
         Debug.Log("Object " + other.name );
         player.transform.parent = other.transform;
        }

So, every time that the player hits a log, the frog becames a child of this log and goes floating with it. And every time that the player moves foward the player parent = null, and when parent = null the player dies. My problem is, some times the frog is on top of the log but they do not collide !! and the player died, but most of the time it works fine. Can someone help me ?

P.S: Sorry for my english.

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
1
Best Answer

Answer by Slev · Oct 01, 2014 at 02:34 PM

It sounds like a logic error to me. We don't want to set the parent to null until we are sure we missed the next log. What I can see happening is you press forward, set the parent to null, then the log detection occurs. Some things like Update() and OnCollisionEnter() are asynchronous. This means we can't be sure (without some controls) which one will be running when. If the Update() loop is what checks null and handles it, it may check before the collision check occurs.

One way to handle this would be a flag that says if we have made a move, if we have, wait for the collision check to occur before handling null. The other way would be to set null in the collision script. Either way I believe your problem is there and in how, and what order, the events "may" occur in.

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 lNeves · Oct 01, 2014 at 09:50 PM 0
Share

Can you give me some suggestions for how to do it ?

avatar image
0

Answer by bubzy · Oct 01, 2014 at 10:00 PM

you are not checking to see what you collided with, just to see if you collided.

 if(other.gameObject.tag != "log") //or whatever
 {
 die();
 }
 else
 {
 player.transform.parent = other.transform;

 }

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 lNeves · Oct 02, 2014 at 11:22 PM 0
Share

Thank you so much !!!!!!!!!!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Selecting Object From Top Causes NullReference 1 Answer

(Solved) Collision happens, but is not detected? 1 Answer

Collision returning an error 0 Answers

GetComponent().enabled = true; 1 Answer

error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected 0 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