0 votes

I have those spherical KinematicBody2D, each moving at same speed along a random vector on stage (based on their rotation when they spawn in).
When collision fires between them, they escape by "sliding over" each other.
I run this piece of code :

var direction
var event = true

func _physics_process(delta):
    if (event):
        direction = Vector2(sin(rotation), -cos(rotation)).normalized()
    var collision = move_and_collide(direction* speed)
    if collision:
        event = false
        direction = direction.slide(collision.normal).normalized()
        #move_and_collide(direction * speed)
        event = true

I use normalized() to get the direction only and set velocity with * speed so the "sliding over" should happen at same speed as when they are just moving around.
If I uncomment the "moveandcollide(direction * speed)" inside the " if collision" statement, they seems to escape faster. How that happens ?
delta is 0.01667s, so it sticks to the frame rate (60 FPS). Does it mean that in one delta time it will execute both moves ?
It may sounds obvious but not to me. Can someone explain ?

in Engine by (37 points)

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.