+1 vote

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:


asked Nov 12, 2019 in Engine by samort7 (13 points)

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.

1 Answer

+1 vote

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:

answered Nov 14, 2019 by thirite (148 points)
edited Nov 15, 2019 by thirite

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

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

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

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()

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.