Laser beam is pushing the enemies [3D]

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

Hello my friends!

I’m developing my first 3D game, and I’m very happy with the results, but some unexpected behavior is worrying me:

The laser beam shot by the hero is pushing the enemies under certain circunstances (jump, cumulative shots, etc). Damn… it’s a laser beam and not a brick.(^_^)

I want to hear from you what can be done to avoid this. I want to remove the mass of the laser beam, but keeping it’s movement and collision.

Thank you in advance.

P.s.: Sorry about my english. Shame on me.

Beam (Rigid Body) <— Maybe this…
---- Collision Shape <— or this…
---- MeshInstance

Enemy (KinematicBody)
CollisionShape
---- Armature
Skeleton
MeshInstance
AnimationPlayer

Hi, i assume you have already changed mass attribute from rigidbody to zero. So the next suggestion i imagine is using kinematicbody instead of rigidbody for beam. Is there any reazon to use rigidbody?

p7f | 2018-12-26 13:21

Hello p7f! Thank you for the answer. There was a reason for me to use the rigidbody, it’s innapropriate, I know (all the physics stuff), but when I tried to use kinematicBody, the enemies instances was desappearing with the laser beam(queue_free). So I’ve decided to left as is. Another point is that the rigidBody mass don’t go to absolute zero. It went to 0.01 and keeping the same behavior. Now I considered using Area as SIsilicon wrote and it works like a charm.

Alex Pires | 2018-12-27 21:51

Yes, i don’t know what i was thinkgin when i said kinematicbody… i always use area for my bullets and etc. If the answer provided by @SIsilicon works, you may select it as best so other see its resolved!

p7f | 2018-12-27 21:56

Ok. Selected! This golden tip will help some beginners since the 3D demo example provided uses something like a ball shoot, and this is a little bit confusing.

Alex Pires | 2018-12-27 22:19

:bust_in_silhouette: Reply From: SIsilicon

I would use an Area instead of a RigidBody. With an Area you can do collision detection, without a collision response; which is what causes your enemies to go back.

For every action there is an equal and opposite reaction.
-Newtons 3rd law

So what you’d do is the change the type of the beam from RigidBody to Area. Its children can stay the same. Then you would attach this script to it.

extends Area

var velocity # you'll have to set this on instancing this node.

func _ready():
    # omit this if you know how to connect signals from the editor.
    connect("body_entered", self, "on_collision")

func _process(delta):
    translation += velocity

func on_collision(body):
    # if the body is an enemy, then remove health from said body.
    queue_free()

The comments are important.

Thank you very much SIsilicon! I was thinking that Area would only work with static objects, but now I can see it works very well with laser beam.

Alex Pires | 2018-12-27 21:56