- Home /
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();
}
}
}
yeah we cant read your code, put it in the code formatting, the little button with binary on it.
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.
i changed force amount nd player rigidbody collision detection is already continuous. Then also same result. with raycast how is it possible?
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.
Here is a nice tutorial on 2D Platformer Collision Detection with Raycasts
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?
Your answer
Follow this Question
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