[Lao Wang’s game development tutorial] Mingchang faces the second bullet Street Fighter 3D: On the birth of a shock wave

The book is followed by "Godot Engine: Using a particle system to achieve a wave of wave fist, yes, it is the hadou gnaw"

Effect picture

Insert picture description here

HadokenBall

Add a script for HadokenBall
Insert picture description here

HadokenBall script

HadokenBall has two states:

  • The state of the ball of luck in the hand: will follow the movement of the hand
  • The state of being separated from the palm: uniform linear motion

The following code is position_refused to obtain the position of the hand. When it is later empty, it means that the HadokenBall has left the hand

#HadokenBall.gd
extends Particles
class_name HadokenBall

var position_ref :Spatial = null

func _ready():
	add_to_group("HadokenBall")

func _process(delta):
	if position_ref != null :
		global_transform.origin = position_ref.global_transform.origin
	else:
		translation += Vector3.RIGHT * 2 * delta

func init_ball(ref):
	position_ref = ref
	transform.origin = position_ref.global_transform.origin
	ref.get_tree().root.add_child(self)

func release_ball():
	position_ref = null

Use the BoneAttachment node to get the position of the hand bone

BoneAttachmentFor the usage of the node, please refer to another blog post by Pharaoh, "Godot Engine: Using BoneAttachment Nodes as Bone Attachments"

Insert picture description here
Rename "BoneAttachment"
Insert picture description here
to "HadokenBallPos" and position "HadokenBallPos" to the right hand

Insert picture description here

Long's code

  • Preload "HadokenBall.tscn" first
  • Define two callback functions for animation callbacks, one for generating HadokenBall.tscn and one for notifying it to leave the hand
#Ryu
extends Spatial

var h_ball_prefab : PackedScene = preload("res://VFX/HadokenBall.tscn")

onready var playback : AnimationNodeStateMachinePlayback = $AnimationTree.get("parameters/playback")


func _ready():
	add_to_group("Ryu")

func do_combo(move_name):
	playback.travel(move_name + "@Ryu")
			
#AnimationPlayer调用		
func make_ball():
	var h_ball : HadokenBall = h_ball_prefab.instance() as HadokenBall
	h_ball.init_ball($rig/Skeleton/HadokenBallPos)

#AnimationPlayer调用		
func release_ball():
	get_tree().call_group("HadokenBall","release_ball")
	

Use AnimationPlayer to set animation callbacks

For details on how to use animation callbacks, please refer to "Godot Engine: Using Call Method Track to Implement Animation Callbacks"

Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/hello_tute/article/details/109383662