0 votes


I have an issue with the normal from collision.normal

Given this piece code :

extends KinematicBody2D

var velocity : Vector2 = Vector2()
var move_speed : int = 60

func _ready():
    velocity = Vector2(3, 6) * move_speed

func _physics_process(delta):
    var collision = move_and_collide(velocity * delta)

    if collision:
        var n = collision.normal
        velocity = velocity.bounce(n)

CollisionShape2D for the ball (circle shape)

Sometimes, after a collision the normal n isn't perpendicular to the plane and he doesn't have a magnitude of 1, wich is not OK for a normal

There is a screenshot just after a collision with the wall to the right (this wall is perpendicular to the x axis).

As you can see :

n.x = -1
n.y = 0.000008
n magnitude ≈ 1.000000000032

Not perpendicular to the right wall, since the right wall is perpendicular to the x axis. normal should be = <-1, 0>
Because of that the velocity isn't the same after a bounce, sure I can round n up or down.

Sometimes the normal is ok, sometimes not. Why is that ?

Godot version 3.2.3.stable.official
in Engine by (12 points)

1 Answer

0 votes

my guess is that the physics implementation have bugs, i was trying something similar relying in have the same value every bounce and it just simply never happened.

by (106 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 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.