Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

godot - What does func _physics_process(delta), move_and_slide(), Vector2() and do in gdscript?

I'm just started learning to program because I want to learn how to make a game. I choose the Godot engine to start making games but I can't understand what anything does. I have only understood the concept of variables and constants. I'm watching a couple of tutorials and copying exactly what the people in the video are doing but I don't just wanna copy and not understand anything, so could you please tell me what the above things even do?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The physics process is called during the physics processing step of the main loop. Physics processing means that the frame rate is synced to the physics, i.e. the delta variable should be constant which isn't the case if you just call _process(delta):

Vector2() is just a 2d vector, the first parameter for the x axis, the second for y. You can use it also as an boolean, Vector(0,0) always returns false, while every other point returns true.

move_and_slide() was designed as a special case, because a common use case was to calculate a slide vector along the collision. However, because it slides, it's possible for there to be more than one collision in a frame (think when you hit a corner between the floor and the wall. For this reason, it can't return a collision, so you need to use the get_slide_collision(). So it handles for example how your character react if he collides with an object.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...