0 votes

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

in Engine by (91 points)

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?

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.

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!

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.

1 Answer

+2 votes
Best answer

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.

by (3,918 points)
selected by

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.

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.