(UNITY2D) How to attract the player to the platform
Hi, I'm trying to figured out how to attract player to the platform in 2D game. I have triangle ship with OverlapCirlce on it bottom part and lot of walls and obstacle. All of these obstacle made by tilemap and have Composite Collider. So idea is that when the ship touches the wall with the collider and the mouse button is pressed, the ship is attracted to the wall at that place.
isTouchingObstacle = Physics2D.OverlapCircle(obstacleCheck.position, checkRadius, whatIsObstacle);
I tryed to do this with add forceMagnitude to the Area Effector 2D, but it's pretty dificult, cause I should add Area Effector to each platform.
forceArea1.forceMagnitude = 10f;
forceArea2.forceMagnitude = 10f;
forceArea3.forceMagnitude = 10f;
Then, I tryed to Lerp player's position to isTouchingObstacle radius, but it's make a lot of bugs.
if (obstacleCheck.rotation.eulerAngles.z < 45f || obstacleCheck.rotation.eulerAngles.z > 325f)
{
transform.position = Vector2.Lerp(this.transform.position, new Vector2(transform.position.x, transform.position.y - .2f), 1f);
transform.rotation = Quaternion.Euler(0, 0, 0);
}
else if (obstacleCheck.rotation.eulerAngles.z > 45f && obstacleCheck.rotation.eulerAngles.z < 135f)
{
transform.position = Vector2.Lerp(this.transform.position, new Vector2(transform.position.x + .2f, transform.position.y), 1f);
}
else if(obstacleCheck.rotation.eulerAngles.z > 135f && obstacleCheck.rotation.eulerAngles.z < 225f)
{
transform.position = Vector2.Lerp(this.transform.position, new Vector2(transform.position.x, transform.position.y + .2f), 1f);
}
else if(obstacleCheck.rotation.eulerAngles.z > 225f && obstacleCheck.rotation.eulerAngles.z < 325f)
{
transform.position = Vector2.Lerp(this.transform.position, new Vector2(transform.position.x - .2f, transform.position.y), 1f);
}
Your answer
Follow this Question
Related Questions
Curved wind in 2D game 0 Answers
Having Problems With Bounce Physics Material 0 Answers
Problems with raycasting 2D. Probelmas com raycasting 2D. 0 Answers
How do I make Polygon Collider 2D more smooth? 0 Answers
Problem with hitboxes and hurtboxes 0 Answers