BoxCollider not blocking other object(s)
I'm really newbie , watched about 20 videos about and tried to do something. But I still have problems with collisions.
I'm working on 2D. I have a Sprite and a Cube. When I click to somewhere at screen, sprite is moving to that position. When sprite hit to cube, it should stop moving (when collision occured) , but instead it's passing through it.
Sprite has these components:
Cube has this components:
BallControl Script
using UnityEngine;
using System.Collections;
public class BallControl : MonoBehaviour {
private Transform tf;
private Rigidbody2D rb;
Vector3 mousePosition;
void Start()
{
tf = GetComponent<Transform> ();
rb = GetComponent<Rigidbody2D> ();
}
void Update ()
{
if (Input.GetMouseButtonDown (0)) {
mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
mousePosition.z = 0f; // Because we are working on 2D
}
transform.position = Vector3.MoveTowards(transform.position, mousePosition, 1.5f * Time.deltaTime);
}
}
Can you tell me why cube's Box Collider not blocking sprite? Should i add something like this to my BallControl script?
void OnCollisionEnter(...)
{
// Stop moving
}
Disabling kinematic and setting Gravity Scale = 0 solved problem but I have no idea , why this problem occurring and how these settings solved the problem.
Answer by kisuke_snow · Sep 13, 2017 at 09:49 PM
You have a 2D Collider on the sprite and a 3D collider on the box. Put them in the same dimension and you are good to go.
Your answer
Follow this Question
Related Questions
2D colliders doesnt work with Gravity Scale = 0 0 Answers
Tilemap Collision 2D colliding with ground. 0 Answers
my colliders don't work properly 2 Answers
boxCollider2D don't move with a tile object 1 Answer
RigidBody Collisions Detect 0 Answers