How to rotate KinematicBody (3D) with precise collision?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Temez1

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
:bust_in_silhouette: Reply From: Magso

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 apply_central_impulse on the ball triggered by an area body_entered signal or timer will suffice and everything else like the stick is just visual.

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!

Temez1 | 2020-03-27 06:29

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()

Magso | 2020-03-27 08:55