|
|
|
 |
Reply From: |
johnygames |
I think the reason why the circles pass through other circles is because you have written a line of code which increases the velocity every tick: velocity.y += gravity*delta
. This causes the circle to gain extremely high speed after a few seconds. Remove that and what you get is smoothly descending circles. I changed your _physics_process() function to:
func _physics_process(delta):
velocity.y = 100
move_and_slide(velocity)
I also noticed you update the position of the circle directly. You should be using the move_and_collide()
function instead. When you update the position of the kinematicbody directly, you override the physics process and that causes glitches.
Does this answer your question?
Thanks for your guidance ; I put the above code in the project . Now the circles are not passing through the collission body. But one problem is that they begin to vibrate after some time of coming down.How to stop the circles from shaking ?
Another problem You told to use move_and_collide() function instead I didn’t understand where to use move_and_collide()
in the programme ?
THE HELIX | 2019-09-28 14:41
You should use the move_and_slide()
method. It should be used right after you have set the velocity vector to whatever speed you wish to have. So something like:
func _physics_process(delta):
velocity.y = 200
move_and_slide(velocity, Vector2( 0, 0 ), true, 2, 0.785398, false)
Take note of the arguments passed in the move_and_slide() method; this might reduce the jittering of the circles a bit.
johnygames | 2019-09-28 20:59
Can you please explain why you used this code
move_and_slide(velocity, Vector2( 0, 0 ), true, 2, 0.785398, false)
as I am new to coding . There is a slight jittering on executing it.
THE HELIX | 2019-10-05 17:45
I used that code so as to set inertia to 0 and reduce the number of collisions. Check the docs Using KinematicBody2D — Godot Engine (3.1) documentation in English
Apparently it doesnt work all that well. I think you need to implement your own physics behaviour when the circles collide. The jittery motion must be attributed to the fact that the circles keep their initial velocity after they have piled up. You could code some behaviour where the circles stop moving if they are too close to one another and start moving again if there is free space around them.
johnygames | 2019-10-06 13:29
Can you please tell how to code such that the circles stop moving if they are too close to one another and start moving again if there is free space around them ?
THE HELIX | 2020-01-24 02:07