网上很多Unity版的刀光效果教程,都是基于粒子系统实现的,我这个Godot版使用Shader结合Tween实现的
节点结构
shader_type spatial; render_mode unshaded,cull_disabled; uniform float offset = 0.0; uniform sampler2D tex : hint_albedo; void vertex(){ UV += vec2(offset,0); } void fragment(){ vec4 c = texture(tex,UV).rgba; ALBEDO = c.rgb; ALPHA = c.a; }Player代码
Player就是模拟一个角色
extends Spatial onready var vfx_slash = $"vfx_slash" func _input(e): if e is InputEventKey and e.pressed and not e.echo: match e.scancode: KEY_1: vfx_slash.play()vfx_mesh代码
extends MeshInstance #var material:Material onready var tween : Tween var percent : float = 0.0 export var duration :float = 0.3 func _ready(): tween = Tween.new() add_child(tween) hide() func play(): show() tween.interpolate_property(self,"percent",0.0,0.5,duration,Tween.TRANS_LINEAR,Tween.EASE_IN) tween.connect("tween_all_completed",self,"tween_all_completed") tween.start() func _process(delta): get_surface_material(0).set_shader_param("offset",percent) func tween_all_completed(): hide()最终效果