0 votes

https://www.dropbox.com/s/e8c4qiwyre9vwxe/Screenshot%202017-05-30%2019.09.56.png?dl=0
I want to create a projectile that collides and hides itself on coliision.
For now, it just fiels trough the collision shape of the enemy entity, and Idk what to do.
As you can see from the screenshot, theres collsion shapes on both the projectile and the enemy. Idk why it shouldnt work ?

in Engine by (17 points)

well you aren't really telling us how you are detecting the collision and what are you doing with it after :)

func _integrate_forces(state):
    print(state.get_contact_count())
    if state.get_contact_count() > 0:
        self.hide()

this is basically the code, I have not a single clue where the problem could originate from.
All the tutorials tell there only should be some collision shapes as child to the colliding objects.

2 Answers

+3 votes
Best answer

There are a lot of ways to detect collision. I have never seen this method.

All I can say is get rid of this method and try this one.

  1. Put a area2d node inside your rigid body. Like so
    RigidBody2d
    ---Collision2d (This is if you don't want the object to go through objects)
    ---Area2D
  2. Now select your Area2D, and go to your Node tab in the editor(It's a tab in the same place as the inspector)

3.You should have signals loaded up. Under Area2D signals there is body_enter( Object area )
Double Click on it.

4.You will get a pop up window, with "please confirm..." select your RigidBody2D
Then at the bottom of the pop up window press connect.

5.Now you should have a body_enter( Object area ) inside your RigidBody2D script.
This is where you can preform your collision functions.

Also for future reference you can have a body_exit( Object area ) in case you want a function to continue until you leave a object's collision.

by (272 points)
edited by
+2 votes

that's definitely not the way to do it. you should set up an area with a collision shape, and connect the body_enter signal to a function, in which we then check which body entered and decide what to do with it.

there are plenty of tutorials on this already, all kind of simple shooters implement this mechanic

by (290 points)

can you give me a link, I have not seen antyhing like this

did you check godot's own official demos? there's a simple space shooter in there

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.