0 votes

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.

in Engine by (842 points)

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

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

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

Please log in or register to answer this question.

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 Frequently asked questions and 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 [email protected] with your username.