Welcome to the forums @Vadim!
Can you explain or show the problem you are having? I haven't had corner shaking problems with Godot, at least not that I know of.
Welcome to the forums @Vadim!
Can you explain or show the problem you are having? I haven't had corner shaking problems with Godot, at least not that I know of.
Ah, I think I see the problem now! The issue is that you are moving into a corner composed of a right angle. This makes it where you push against one of the two walls in the angle, pushing you against the other wall, which pushes you out of the corner, but because you are moving forward, you push into the wall, repeating the cycle. In other words, something like this is occurring (apologizes for the horribly programmer art :lol: ):
In the picture, the lighter lines are to represent the bounce/slide velocity while the circles are the positions at each bounce/slide. If it was a perfect bounce, then the player would actually stay frozen since the bounces would form a right angle (like in the picture above) but because this is not happening, the player is jittering around in the corner. The player is constantly moving from the blue circle to the red circle, from red to green, and then back to blue (though with slight offsets due to the angles).
I'm not sure right off what the best way to fix this would be, but one possible way would be to make a very small raycast in front of the player motion, and if there is something in the way, to cancel the velocity in that direction. This would prevent the loop in the corner, since the raycast would see the wall and stop the player from bouncing around.
move_and_slide()
returns a Vector3 which represents the linear velocity of your KinematicBody after the physics engine has moved it. If your character slides along a surface, this will affect the direction and length of the return value. This also means that if your body is walking into a wall, the length of the return value will be smaller than the velocity
parameter you passed in. Otherwise, if there were no obstacles along the way, the value returned by the method will be the same as the parameter that you passed in.
Previously, my Kinematic characters had issues with jitter because I didn't bother to cap their speed when attempting to move into corners, which led to the cycle that TwistedTwigleg described above. Fortunately, by using the return value from move_and_slide()
you can easily limit the body's speed without needing to do any special checks for collisions.
For this to work, your KinematicBody will need some sort of variable to keep track of the player's velocity. I'll call it velocity
in these examples. velocity
should at the very least be affected by the player's input, but you may want it to be affected by other things depending on what physics behavior you're going for.
After applying all the movements that you want to velocity
, all you have to do to prevent velocity
from exceeding what is physically possible is to set it to the return value of move_and_slide
like so:
velocity = move_and_slide(velocity)
@Vadim said: Here is my code linear_velocity = move_and_slide (linear_velocity, Vector3.UP, true, 4, deg2rad (45)), unfortunately this doesn't work :(
What does your code to move the player according to input look like?
Hey I wasn't able to find a necro rule (apologies if its frowned upon here), but as as this is still unanswered, and one of the results that a web search brought me to for this question, I figured I'd put in my two cents:
@Vadim Have you tried switching your 3D physics in project settings from "DEFAULT" or "Bullet" to "GodotPhysics"?
I had this same issue when move_and_sliding a KinematicBody into a corner, or at a shallow angle along a wall, and it looks like Bullet might be to blame with the other default configurations, as switching back to GodotPhysics removed the stuttering.
Currently in v3.4.stable.official [206ba70f4]
i wrote my code and it works
func m(p_linear_velocity : Vector3, p_floor_direction : Vector3, p_stop_on_slope : bool, p_max_slides : int, p_floor_max_angle : float, p_infinite_inertia : bool):
var lv = p_linear_velocity;
var motion = lv * get_physics_process_delta_time();
while(p_max_slides > 0):
var collision;
collision = move_and_collide(motion,p_infinite_inertia,true,false);
if !collision:
motion = Vector3();
else:
motion = collision.remainder;
p_max_slides -= 1;
return lv;
)
I just removed the slide