- Home /
Move ball to mouse while still getting stuck on collision
I have a ball that the player can grab and move around. It's always being moved to the mouse position, regardless of wheter the ball is being moved through collision. I don't want that to happen. The ball has a RigidBody2D and a CircleCollider2D. This is my code:
private void OnMouseDrag()
{
Vector2 mouseInWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition);
playerTf.position = new Vector3(mouseInWorld.x, mouseInWorld.y, 0);
}
So I basically I want the ball to still get stuck on collision, when setting it's position.
Comment
Best Answer
Answer by SchredDev · Jan 17, 2020 at 07:48 PM
Stack Overflow saves the day: https://stackoverflow.com/questions/59792916/how-to-move-a-rigidbody2d-to-a-position-while-still-checking-for-collision