Weird physics stuttering...bug?

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

I’ve been recreating a game, but I encountered some weird physics behavior.
The problem:
When the ball falls into the hills, it calculates the normal of the current point of the shape and sets its linear velocity to it. This should cause the ball to follow the outline of the collision shape, which it does. However, there’s some weird bouncing going on, when it reaches higher speeds, which eventually causes the ball to bump into the hill.

You can take a look at the project, just hit play and see.

If you want that much control over the ball I think you’d be better off with a KinematicBody2d.

mateusak | 2018-02-12 18:02

Yeah, I’ll keep that in mind with my next project! Thanks alot!

Footurist | 2018-02-12 22:35

Yeah… listen, I really don’t think you have a choice. A RigidBody2D uses so much more CPU, and it’s simply impossible to achieve what you want without bugs using it. It’s simple to change, really. Here is a class I made, you can inherit from it. I made it so it’s pretty simple to use.

extends KinematicBody2D

var outer_forces = Vector2(0, 0)

func move(_floor_normal = Vector2(0, 0), _slope_friction = 21, _max_bounces = 4, _floor_max_angle = 1.0472):
	outer_forces = move_and_slide(outer_forces, _floor_normal, _slope_friction, _max_bounces, _floor_max_angle)

func apply_acceleration_x(_value):
	outer_forces.x += _value

func apply_impulse_x(_value):
	outer_forces.x = _value

func apply_force_x(_value):
	outer_forces.x = lerp(outer_forces.x, _value, 0.5)

func apply_acceleration_y(_value):
	outer_forces.y += _value

func apply_impulse_y(_value):
	outer_forces.y = _value

func apply_force_y(_value):
	outer_forces.y = lerp(outer_forces.y, _value, 0.5)

If you’re going to switch, I’d recommend a gravity of 20. Just apply_acceleration_y(20) every _physics_process

mateusak | 2018-02-13 14:12