0 votes

Hey!

I'm trying to do a top-down mini golf game to learn the Godot engine. So the question is that how to rotate KinematicBody precisely so that it collides the ball every time. Now it collides only when the rotation speed is low enough. With higher speeds, it goes through.

If I understand the physics engine right it doesn't recognize the collision because the stick clips inside the ball between frames. So the question is how this should be done? I didn't figure out how move_and_collide() would help me in this situation because I'm not moving the stick. I'm just rotating it so it can hit the ball. Here's a pic from the side angle if it helps

And here is the current code. I tried to do the same with rotate_object_local() without success.

extends KinematicBody

const LOOKAROUND_SPEED = 0.01
var mousePos = Vector2()

func _physics_process(delta):
    rotate_z(mousePos.x*LOOKAROUND_SPEED)
    rotate_x(-mousePos.y*LOOKAROUND_SPEED)
    mousePos = Vector2()
    transform = transform.orthonormalized()

func _input(event):
    if event is InputEventMouseMotion:
        mousePos = event.relative
asked Mar 25 in Engine by Temez1 (15 points)

1 Answer

+2 votes
Best answer

Try not to rely on the physics engine too much like this. I'm not saying the physics aren't capable but in this circumstance using applycentralimpulse on the ball triggered by an area body_entered signal or timer will suffice and everything else like the stick is just visual.

answered Mar 26 by Magso (2,505 points)
selected Mar 27 by Temez1

Hey,

thanks for the answer! I will try to use that workaround and I'm pretty sure it will work. I have to say that initially, I was looking for some physics-based solution as the problem seems pretty simple (or is it?). This type of solution might come handy in other collision situations too so thanks for that!

The only physics based solution would be to increase the physics fps but this would slow everything down except node's using methods that directly set their position like Translate()

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 How to use this Q&A? before posting your first questions.