This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hello everyone !
I make my first step in 3D game by making a pong with a little twist : player can rotate her paddle thank to left and rigth key, to give additional velocity when hitting the ball, and the ball can rotate a paddle by pushing the paddle on the impact point.

I was thinking of doing it by creating a rigid body for the paddles, and a kinematicBody for the ball. When the ball hits a paddle, in its code, I look to see if the object that collided is a rigidBody, and if so, I apply an impulse on the collision point with the normal racquet normal * the speed of the ball.

But the racket doesn't move.

I tried to move a rigidBody with a kinematic on another project (a platform game where a player can move a ball), and it works, the rigidBody move.

Do you have an idea?

in Engine by (15 points)

Can you provide the relevant portion of your code? Is the collision detected correctly?

The collision is detected yes.

func _physics_process(delta: float) -> void:
    var collision = move_and_collide(velocity * delta, false)

    if collision:
        if collision.collider is RigidBody:
            collision.collider.apply_impulse(collision.position, -collision.normal * 100)
            velocity = velocity.bounce(collision.normal)
        else:
            velocity = velocity.bounce(collision.normal)

Rigidbody is the paddle

1 Answer

0 votes
Best answer

You're using the position-information of a KinematicCollision2D:

The point of collision, in global coordinates.

However, you use it as the offset-vector for apply_impulse:

The position uses the rotation of the global coordinate system, but is centered at the object's origin.

So you need to calculate the offset yourself:

var offset = collision.position - collision.collider.global_position
collision.collider.apply_impulse(offset, -collision.normal * 100)
by (10,634 points)
selected by

Thank you, that solve my problem !

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.