Hello. I am building a pinball-style demo, using RigidBody2d for the ball and KinematicBody2Ds for the flippers. So far the response on contact is great but I am trying to make it to where the RigidBody's velocity increases after each flipper contact (provided it is in "_isForce" state). I saw set_bounce
as a method and while it does what I need to, it is deprecated in the upcoming versions and I need to know the right way to do it. All help appreciated.
The _isForce
variable on the flippers only triggers for a brief while after input. It is working fine so no need for it here. Also: the collisions count is just for debugging so I can make sure things are hitting right. My pinball is reporting collisions, but only one at a time.
BALL code
extends RigidBody2D
var _collisions = 0
var _bounceForce = 0.05
var _forceMultiplier = 1.5
func _on_Pinball_body_entered(body):
if body.name == "LeftFlipper" or body.name == "RightFlipper":
if body._isForce:
_bounceForce = _bounceForce*_forceMultiplier
_collisions = _collisions+1
set_bounce(_bounceForce*_forceMultiplier)
func _bounceForceFixer():
if _bounceForce < 0:
_bounceForce = 0
elif _bounceForce > 1:
_bounceForce = 1
func _process(_delta):
_bounceForceFixer()