Box Collider 2D not functioning - Object bound to mouse,Box Collider 2D not functioning - object bound to mouse
Hi all. So i have an object that tracks to the mouse's location and walls made of box colliders. When the mouse is moved past the point the object would be stopped by the colliders, the object seems to "squeeze" through it. It isnt stopped by it but it only seems to reduce its speed and offsets it from the mouse ( https://youtu.be/qAqoEOxetU4 ). Could i solve this by bouncing the object off the collider or is there another way of stopping it? Very new to unity so please excuse some poor coding. Thanks.
public class PlayerSquare : MonoBehaviour {
private Vector2 mousePosition;
public float moveSpeed = 1f;
private TrailRenderer trail;
private SliderValue slidervalue;
void Start()
{
trail = GetComponent<TrailRenderer>();
}
// Update is called once per frame
void Update() {
transform.Rotate(Time.deltaTime, 0, -2);
mousePosition = Input.mousePosition;
mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
transform.position = Vector2.Lerp(transform.position, mousePosition, moveSpeed);
}
Your answer
Follow this Question
Related Questions
Why/How 2d tower of blocks collapse? 0 Answers
A 2D Character Controller with Rigidbody2D.AddForce 2 Answers
WheelJoint2D rotates parent object 1 Answer
Reduce distance between two Vectors 1 Answer
Getting rid of 2D collision jitter 1 Answer