- Home /
Question by
ahmedkhalil11 · Nov 22, 2018 at 11:26 PM ·
c#unity 2d
The snail makes a weird behavior when the player push it
I have a problem when I push the snail when she is stunned and at the same time when the player moves to the snail, the snail makes a weird behavior.
could you help me solve this problem or just tell me where is the problem to solve it because I can't see what happen
RaycastHit2D leftHit = Physics2D.Raycast(left_Collision_Position, Vector2.left, 0.2f, PlayerLayer);
RaycastHit2D rightHit = Physics2D.Raycast(right_Collision_Position, Vector2.right, 0.2f, PlayerLayer);
Collider2D Tophit = Physics2D.OverlapCircle(top_Collision.position, 0.2f, PlayerLayer);
if (leftHit)
{
if (leftHit.collider.gameObject.tag == MyTags.PLAYER_TAG)
{
if (!stunned)
{
// dammage the player
leftHit.collider.gameObject.GetComponent<PlayerDamage>().DealDamage();
}
else
{
if (gameObject.tag == MyTags.SNAIL_TAG)
{
myBody.velocity = new Vector2(15f, myBody.velocity.y);
}
}
}
}
if (rightHit)
{
if (rightHit.collider.gameObject.tag == MyTags.PLAYER_TAG)
{
if (!stunned)
{
// dammage the player
rightHit.collider.gameObject.GetComponent<PlayerDamage>().DealDamage();
}
else
{
if (gameObject.tag == MyTags.SNAIL_TAG)
{
myBody.velocity = new Vector2(-15f, myBody.velocity.y);
}
}
}
}
I have recorded The detail of the problem by a video: here
The project here
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612182611im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to create a field of view for enemy ai that detects a player Unity 2d? 3 Answers
Instantiated object not showing in scene or hierarchy 2 Answers
,How to stop jump animtion 1 Answer