+2 votes

Trying to make a pinball game.

Currently just testing with a ball (RigidBody2d) and a flipper(Kinematic2d).

The flipper arc goes from -244 degrees to 60 degrees.
This is within the Physics_Process. I've set the flipper to syncing motion to physics as well as moving the ball to a higher process priority

Setting the rotation essentially clears the flipper and puts it at the new angle, with no collisions detected.

Ive tried basically a manual tween, where I set a state of swinging = true, and then on delta frames use a swing method to increment rotation by 0.18. Works, but the flipper can miss, so I tried tweening.

Tweening the sprite and collider seems better, but occasionally the flipper locks up. Though its my first time using tween, so I could be doing something weird. I tried the 1.1 multiplier, thinking if the collider moves faster that I could get the spot where I'm missing the ball.

if Input.is_action_just_pressed("ui_left"):
    if rotation != -rot_cap:
        if !tween.is_active(): 
            tween.interpolate_property(get_node("/root/Main/YSort/LFlipper"),"rotation",null, -rot_cap, tween_speed)
            tween_coll.interpolate_property(get_node("/root/Main/YSort/LFlipper/Flipper/CollisionShape2D"),"rotation",null, -rot_cap, tween_speed*1.1)

    tween.reset(self, "rotation")
    tween_coll.reset(self, "rotation")

Ive also tried setting up an area2d for the swing path and detecting if the ball is in it, which still may be a workaround, just need to wrap my head around all the physics behind the hit.

Also starting to think of going back to switching the Flipper to a RigidBody and messing with Torque values. Although when I tried this last I also had the issue of the ball pushing the flipper, but I think I can solve that with a linear damp?

in Engine by (18 points)

2 Answers

0 votes

I wasn't able to reproduce your issue. But the following setup worked for me:

RigidBody2D with a physics material override, with bounce=1
Child: CollisionShape2D

KinematicBody2D with children Tween and CollisionShape2D and

func _physics_process(_dt):
    if Input.is_action_just_pressed("ui_left"):
        $Tween.interpolate_property(self, "rotation", 0, PI, tween_speed)
by (68 points)
0 votes

KinematicBody2D doesn't interact with RigidBody2D on its own, you have to code the interaction yourself. Your flipper is pushing the ball only because it tried to move inside the rigid body, and so the rigid body was pushed away by the physics engine. Your flipper is not applying forces to the ball properly.

There is a whole tutorial for kinematic and rigid body interaction on kids can code

You can also just make your flipper a rigid body and experiment with joints if you'd like.

by (29 points)
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.
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 webmaster@godotengine.org with your username.