Say I have two KinematicBody2D, one on the left remaining still and one moving to the left from the right.
The one on the right moving to the left
func _physics_process(delta):
var p = position
var pad_collision = move_and_collide(pad_velocity * delta)
if pad_collision:
if pad_collision.collider.get_name() == "Ball":
print("The position of the pad before collision is: ", p)
print("The position of the pad after 1st calculation is: ", position)
The still object:
func _physics_process(delta):
var p = position
var collision = move_and_collide(Vector2())
if collision:
print("The position of the pad after 2nd calculation is: ", collision.collider.position)
pass
The console showed some interesting result:
Here I just show the first 5 lines because the rest of the lines are just the same
The position of the pad before collision is: (78.666672, -232)
The position of the pad after 1st calculation is: (72.026047, -232)
The position of the pad before collision is: (72.026047, -232)
The position of the pad after 1st calculation is: (72.02092, -232)
The position of the pad after 2nd calculation is: (72.02092, -232)
Basically 78.666672 is the x coordinate at the start of the frame when 'move_and_collide()' interpreted that the moving object will collide with the still one, and 72.026047 is the value after stopping right in front of the object (end of the frame). The third and fourth are just similarly done. I originally expected the fourth line would be:
The position of the pad after 1st calculation is: (72.026047, -232)
but the position turns out to be 72.02092 < 72.026047 which is weird
If the console output gives the first two lines then 72.026047 then this value should be the boundary because according to official docs, move_and_collide()
will make it stop right at the boundary!
How come the KinematicBody2D can still go further than the boundary set by CollisionShape2D?
I understand the error is quite small in this case, but if the both object have both x and y velocity vectors and collide head on, the error would be much larger (I tested it, about 0.4 in my case and both objects are pushed from each other just like sliding, but I did not code any collision response to control the movements).
Sometimes the fourth line will gives a value slightly larger than 72.026047 eg 72.03
Any experienced godot coders can tell why?
If the physics is like this, then I reckon I need to redo all physics again purely in _process() ...