Godot放慢了区域2D对象
我正在为我的2D自上而下的太空游戏制作一个原型,并且我将aquare2d用于 *船对象,因为它的大多数机械师仅依靠碰撞。有什么办法可以放慢脚步,然后在发射船后停止,因为现在它只是连续飞行。 这是我的基本代码:
var jump_speed = 500
var velocity = Vector2()
func get_input(delta):
if Input.is_action_pressed("click"):
look_at(get_global_mouse_position())
if Input.is_action_just_released("click"):
velocity = transform.x * jump_speed
func _physics_process(delta):
get_input(delta)
position -= velocity * delta```
I'm making a prototype for my 2d top-down space game and I'm using area2d for my *ship object since most of its mechanics rely only in collisions. Is there a way i can slow down then stop my ship after it is launched, because as for now it just fly continuously.
Here is my basic code:
var jump_speed = 500
var velocity = Vector2()
func get_input(delta):
if Input.is_action_pressed("click"):
look_at(get_global_mouse_position())
if Input.is_action_just_released("click"):
velocity = transform.x * jump_speed
func _physics_process(delta):
get_input(delta)
position -= velocity * delta```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
总的来说,这个想法是随着时间的推移降低
velocity
向量的长度。我们可以为此定义减速(这不是唯一的方法):然后,在
_PHYSICS_PROCESS
中,我们可以通过减少velocity
的数量来计算:将其与
velocity
的量表进行比较,如果是更多,只需将velocity
设置为vector> vector2.zer.zer.zer.zero
否则我们要缩放速度
适当:顺便说一句,从godot 3.5开始,
limit_length
vector2
和vector3
使这个更简单地实现。In general the idea is to reduce the length of the
velocity
vector over time. We could define a deceleration for that (this is not the only way to go about it):And then in
_physics_process
we can compute by how much thevelocity
would be reduced:Compare it with the magnitud of
velocity
, if it is more, just set thevelocity
toVector2.ZERO
otherwise we want to scalevelocity
appropriately:By the way, from Godot 3.5 onward there is a
limit_length
method inVector2
andVector3
that can make this simpler to implement.