![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Dupy |
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?
Can you provide the relevant portion of your code? Is the collision detected correctly?
njamster | 2020-03-19 15:51
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
Dupy | 2020-03-19 16:39