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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Ekta-Mehta-D · Apr 18, 2014 at 10:59 AM · gamelayerslogic

Doodle Jump game issue

Hello everyone..

i am working on doodle jump type of game.. i stuck at one issue..

Actually i implemented layer based collision so that player pass through the platform. my player is in "player" layer and platforms are in "platform" layer .. When player jumps i am changing its layer and when players velocity get negative then again i change player layer to "platform"

but when player collides with coin i want my player to behave like he should continue to collides with coin which are coming in his way nd force also will be added to the player.

My issue is that player collides with coin only once nd then bcz of force/jump he pass through all the coins coming in his way. I dnt want that.

He should collect all the coins. I dont understand how to solve this issue.

Please help me guys if u have solution of my problem..

Thanks in advance for your support and help.

 function Update () 
 {
     if(gameScript.gameStarted)
     {
         if(player.gameObject.rigidbody.velocity.y < 0 && player.gameObject.layer == 8)
     {
         player.gameObject.layer = 9;
         ChangeChildLayerToPlatform();
     }
         }
 }

 function OnTriggerEnter(other : Collider)
 {
     if(other.gameObject.tag == "platform" )
 {
     if(other.gameObject.name == "Platform(Clone)" || other.gameObject.name=="platformMoving(Clone)" ||  other.gameObject.name == "BasePlatform" || other.gameObject.name == "basePlatform(Clone)")
     {
         player.gameObject.rigidbody.velocity = new Vector3(0, 0, 0);
         player.gameObject.rigidbody.AddRelativeForce(0 , 580 ,0);
         player.gameObject.layer = 8;
         ChangeChildLayerToPlayer();
         //scoreScript.Score+=5;
     }
     else if(other.gameObject.name == "platformObject(Clone)")
     {
         player.gameObject.rigidbody.velocity = new Vector3(0, 0, 0);
         player.gameObject.rigidbody.AddRelativeForce(0 , 2000 ,0);
         player.gameObject.layer = 8;
         ChangeChildLayerToPlayer();
     }    
  }
 } 

Comment
Add comment · Show 3
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 HarshadK · Apr 18, 2014 at 11:08 AM 0
Share

Can we see your code?

avatar image joshmann971 · Apr 18, 2014 at 11:33 AM 0
Share

yeah we cant read your code, put it in the code formatting, the little button with binary on it.

avatar image Ekta-Mehta-D · Apr 18, 2014 at 11:51 AM 0
Share

Can anybody help me?

1 Reply

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

Answer by HarshadK · Apr 18, 2014 at 12:14 PM

Looking at the amount of force that you are adding to your player, the issue seems to be that physics engine is not able to detect collision between player and your coin object.

One solution to this is to set the Collision Detection of your player to either Continuous or Continuous Dynamic as per the requirements in your game. Refer this Ridigbody documentation for that.

Let us know if it solves your problem. If this still does not solve the issue then you might need to use RayCast to detect the possibility of collsion beforehand and handle it.

Comment
Add comment · Show 7 · 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 Ekta-Mehta-D · Apr 18, 2014 at 12:18 PM 0
Share

i changed force amount nd player rigidbody collision detection is already continuous. Then also same result. with raycast how is it possible?

avatar image HarshadK · Apr 18, 2014 at 12:26 PM 0
Share

You can cast a ray from your player to the intended direction with the distance as required for the expected collision. Then check with the raycast if your player object will hit that coin and if it is supposed to hit the coin then you can make the character collect the coin. You need to set the distance equal to the amount the player is expected to move in a frame so that you can detect the collision beforehand and work accordingly for collision with each coin.

avatar image Ekta-Mehta-D · Apr 18, 2014 at 12:30 PM 0
Share

ok. Thanks mate for making me understand..

avatar image HarshadK · Apr 18, 2014 at 12:31 PM 1
Share

Here is a nice tutorial on 2D Platformer Collision Detection with Raycasts

avatar image Ekta-Mehta-D · Apr 18, 2014 at 12:42 PM 0
Share

Ok. will it work for all layers ? or i will make different layer for coin nd within that distance if i find coin that collect it in that layer. is it so?

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

21 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

Related Questions

A node in a childnode? 1 Answer

I can't go back to the start up screen after hitting not now 0 Answers

How much money can I make for a good game in Unity Union? 1 Answer

Incremental game need help 1 Answer

Dynamic Layer Switching Performance 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