- Home /
CircleCast hits emitter with Collider2D
Hi guys,
I'm trying to write custom physics for my game. I wish to make my balls bounce from colliders and I've done it perfectly but there's a problem when I add circle collider to ball.
It seems, circle cast I use effects from circle collider. Therefore my whole collision detection algorithm collapses. I need to understand how not to make circle cast effected by circle collider.
Here's code I wrote, Update calls this as a seperate method.
void PhysicsController () {
//Debug Drawing
direction_on_surface = global_utilities.Utility.DirectionReposition(transform.position, ball_rigidbody.velocity, 0.5f);
RaycastHit2D hit = Physics2D.CircleCast (transform.position, 0.5f, Vector2.zero, 0.5f);
if (Physics2D.CircleCast (transform.position, 0.0005f, Vector2.up)) {
if (hit.transform != hit_object && hit.transform != null) {
//Hit behaviour for walls;
if (hit.transform.tag == "wall") {
ball_rigidbody.velocity = Vector2.Reflect(ball_rigidbody.velocity, hit.normal);
}
}
}
}
Your answer
Follow this Question
Related Questions
Is my 2D Raycast set up correctly? because it does not seem to hit anything when i use a layer mask. 1 Answer
Raycasting in 2D to prevent a player from moving through walls? 1 Answer
Issue with Raycasts in Unity 2D 2 Answers
OnTriggerEnter2D triggers before the collision 1 Answer
How come people prefer to use rays for 2d collision instead of edge colliders? 1 Answer