How to find coordinates on opposite side of a shape?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By samort7

I have an Area2D bullet colliding with a KinematicBody2D zombie. The zombie has a CircleShape2D collision shape.

What is the best way to locate the point on the circle opposite the bullet so that I can spawn a blood particle effect?

Here’s an illustration of what I am trying to do:


Maybe calc a point which is a continuation of the bullets path with a distance of the shapes maximum width (maybe slightly longer) then from there do a raycast2d in the opposite direction. (back).
If you have the direction Vector2 of the bullet, you get the distance Vector somehow like: Direction.normalized()*ShapeWidth.
May fail if another shape is very close (raycast will hit that instead).

Maybe too complicated & there’s a much easier way, therefore only as comment.

wombatstampede | 2019-11-13 08:42

:bust_in_silhouette: Reply From: thirite

Turns out the solution is some fairly simple rotations:

  • hitCircleRadius : the radius of the hitcircle collider
  • hitAngle : the angle from the hitcircle centre to the bullet center, on impact
  • bulletAngle : the angle of the bullet’s velocity
    var exitPoint = Vector2(0,hitCircleRadius).rotated(-hitAngle).rotated(bulletAngle*2)

Example project available here:

Is there a way to get the angle of impact for a CircleShape2D?

samort7 | 2019-11-14 23:46

The ‘angle of impact’ will be the bulletAngle described above. hitAngle describes the point on the circle’s radius the bullet hit, bulleAngle is the angle the bullet hit it at. Edit: converted vars from snake-case to camel-case as this forum seems to have serious issues with underscores

thirite | 2019-11-15 08:23

Been working on this for a couple days now. Just not sure how to get hitAngle and bulletAngle. Any tips?

samort7 | 2019-11-18 05:04

When the bullet hits an actor, take the position of the actor and find the angle to the position of the bullet. That will be the hitAngle.
eg: var hitAngle = actor.position.angle_to(bullet.position)
bulletAngle will then literally be the angle of the bullet’s velocity.
eg: var bulletAngle = bullet.velocity.angle()

thirite | 2019-11-18 07:28