Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Robster | |
Old Version | Published before Godot 3 was released. |
Hi all…
Still working on Pong. Harder than I thought, great learning experience though.
I have a ball
which is a RigidBody2D
. It bounces around nicely.
I have some bat
s. They are KinematicBody2D
. They are controlled nicely now with keyboard, mouse and touch. So far so good.
I also have two wall
s and the ball bounces nicely off the wall. The bat also stops when it hits the wall. The whole thing is just smooth as silk. The days are looking bright!
Here’s an example of each:
Ball:
- RigidBody2D
– sprite
– CollisionShape2D
Bat:
- KinematicBody2D
– sprite
– CollisionShape2D
Wall:
- Node2D
– Sprite2D
– StaticBody2D
– CollisionShape2D
They work nicely. I’m happy.
So now, within the bat
, I’m trying to determine what we’re hitting (wall or ball) and then soon, where.
This is my code:
#let's see if the ball hit the bat
if bat.PlayerNumber == 1:
if bat.is_colliding():
print("collision event captain!")
bat.get_collider()
print("colided with: ", str(bat.get_collider()))
Result:
- If
bat hits wall.
All strings display including the collision object - If
bat hits ball
. Nothing is displayed. Nocollision event captain!
or anything after.
It has to be a beginner mistake. Can anyone spot what it could be?
The bat will not go through the wall. The ball bounces off the bat. It’s all working well. Just no collider info is returned.
Any advice will be lapped up.