I want to make a Flappy Bird game i have the player that is RigidBody2D and pipes they are KinematicBodys2D.
When im trying to detect collision from pipe script with collision = move_and_collide() it`s just dont detect collisions with RigidBody2D
Collision between RigidBody2D and Kinematic Body2D
Collisions between a RigidBody2D and a KinematicBody2D should work.
What is a pipe script?
Can you post your project somewhere so that we can see it?
I think OP means the script attached to the kinematic bodies (the pipes) in the flappy bird game...
DaveTheCoder
sorry for late answer
Here's where I learned it... https://kidscancode.org/godot_recipes/physics/godot3_kinematic2d/
- Edited
I'll repeat: Can you post your project somewhere so that we can see it? Or another minimal project that has the issue? (Don't include the .import subfolder.)
There are various reasons why it could be failing to work. Seeing the whole project makes it much easier to find the cause.
- Edited
DaveTheCoder Sorry, i thought it is only code issue
I wasn't able to extract the files from the .rar. But maybe someone else can look at it.
Are you using C# scripts in the project? It has a .mono subfolder.
DaveTheCoder I wasn't able to extract the files from the .rar
- Edited
DaveTheCoder No, im using GDScript
I was able to duplicate the problem. I can see the objects colliding visually, but move_and_collide() returns null. I don't know why.
DaveTheCoder very sad, so i am going to do player KinematicBody and move it down every frame
Shouldn't you be able to get a collision directly from the physics server?
- Edited
It occurred to me that the problem may be that the KinematicBody2D is pushing the RigidBody2D away, so that their collision shapes never actually overlap.
If I change the mode property of the RigidBody2D to MODE_KINEMATIC, then the RigidBody2D doesn't get pushed, and a collision is detected. However, the collision shapes doesn't overlap in this case either, so my reasoning above may be faulty.
- Edited
Ok, this worked... in Player.gd:
extends RigidBody2D
func _ready():
pass
func _integrate_forces(state):
if Input.is_action_just_pressed("Jump"):
apply_impulse(Vector2.ZERO, Vector2(0, -300 - linear_velocity.y))
func _physics_process(delta):
var crash = get_colliding_bodies()
print(crash)
pass
● Array get_colliding_bodies() const
Returns a list of the bodies colliding with this one. Requires contact_monitor to be set to true and contacts_reported to be set high enough to detect all the collisions.
Note: The result of this test is not immediate after moving objects. For performance, list of collisions is updated once per frame and before the physics step. Consider using signals instead.