godot实现跳一跳蓄力跳跃

本文介绍了如何在Godot游戏引擎中使用PathFollow2D组件创建动态路径,通过`func_ready`设置起点,`func_process`处理用户输入(空格键控制计时和路径调整),实现路径跟随动画。
摘要由CSDN通过智能技术生成
extends Path2D

var time


func _ready():
	curve.add_point(Vector2(0,0),Vector2(0,-100),Vector2(0, -100),0) #起始点
	pass



func _process(delta):
	if Input.is_action_just_pressed("ui_accept"):#按下空格监听,打开计时器,要改变Timer的默认值
		print("start")
		get_node("PathFollow2D/Sprite2D/Timer").start()
	if Input.is_action_just_released("ui_accept"):
		time=get_node("PathFollow2D/Sprite2D/Timer").wait_time-get_node("PathFollow2D/Sprite2D/Timer").time_left #获得按空格时间
		curve.add_point(curve.get_point_position(0)+Vector2(time*400,0),Vector2(0, -time*400),Vector2(0, -time*400),1)#设置落点
		print(time)
		get_node("PathFollow2D").progress_ratio=0#准备开始偏移
	if get_node("PathFollow2D").progress_ratio!=1 :
		if get_node("PathFollow2D").progress_ratio<=0.3:
			get_node("PathFollow2D").progress_ratio+=0.02
		else:
			get_node("PathFollow2D").progress_ratio+=0.01
	else:
		curve.remove_point(0) #删除起始点确保不回到原点
	pass

节点设置如下图:

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值