Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A 3D character walking in a world using Godot #62

Closed
acs opened this issue Oct 13, 2022 · 7 comments
Closed

A 3D character walking in a world using Godot #62

acs opened this issue Oct 13, 2022 · 7 comments
Labels

Comments

@acs
Copy link
Contributor

acs commented Oct 13, 2022

There are several strategies for implementing the 3D character walking. Some quick ideas:

  • The key animation is the one simulating the step by step animation: this animation could be very high level if the character details are few (for example, if it is just a skeleton with two legs, two arms, a body with a bone, and a header). Or it could be very complex if we include the feet and knees and hips and arms and head movements
  • In parallel to this animation, the character must move as a result of walking.

Both animations must be synced. If the walking stop, the step animation stop. The step animation must continue from the last point.

There are other details like howto animate the changes of directions when walking. But let's go step by step 😄

The real work will be done in #69

@acs
Copy link
Contributor Author

acs commented Oct 13, 2022

For example, I have imported from Mixamo this walking animation:

Screencast.from.14-10-22.00.10.50.webm

The animation is a complete cycle of the two steps, the basic animation for walking. And it has the animation for the parts but also the movement of the character. So it is fully done. What is pending? To redo the animation starting from the last point the character was. And to use the keys, you can start, stop the animation from the last status of it.

Let's try to implement with GDScript:

  • Play the animation in loop so the character walks at infinity
  • Use keys to start/stop the animation
  • Understand if we can rotate and the animation is credible

@acs
Copy link
Contributor Author

acs commented Oct 13, 2022

Once we have ended playing with the Mixamo animation, the goal is to create our own with totally free models, and doing the animation from scratch, which is not something easy.

@acs
Copy link
Contributor Author

acs commented Oct 14, 2022

Ok, things progressing as expected:

Screencast.from.14-10-22.19.11.14.webm

Just needed a bit of GDScript to make the two steps animation to become a real walking:

extends Node3D

const step_distance = 1.5

# Called when the node enters the scene tree for the first time.
func _ready():
	var boy_anim_old = $AnimationPlayer.get_animation("Armature|mixamocom|Layer0")
	boy_anim_old.set_loop_mode(0)
	# $AnimationPlayer.add_animation("move_new", boy_anim)
	$AnimationPlayer.play("Armature|mixamocom|Layer0")

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	if !$AnimationPlayer.is_playing():
		var pos = $Armature.get_global_position()
		var new_pos = Vector3(pos.x, pos.y, pos.z + step_distance)
		$Armature.set_position(new_pos)
		$AnimationPlayer.play("Armature|mixamocom|Layer0")

@acs
Copy link
Contributor Author

acs commented Oct 14, 2022

Next natural step is howto combine transformations. Probably if all the animations has a rest pose we can start from it to change between animations. But the idea is to have several animations sharing the same skeleton. Not sure if this could be possible with Mixamo in its free version.

And yes, it is possible at least in Blender:

https://www.youtube.com/watch?v=fLfjHzJy2A0

@acs
Copy link
Contributor Author

acs commented Oct 15, 2022

The GDScript for Godot 3.5.1:

extends Spatial

const step_distance = 1.5

# Called when the node enters the scene tree for the first time.
func _ready():
	var _anims = $AnimationPlayer.get_animation_list();
	var boy_anim_old = $AnimationPlayer.get_animation("Armature|mixamocom|Layer0")
	var boy_anim = Animation.new()
	boy_anim_old.loop = 0
	# $AnimationPlayer.add_animation("move_new", boy_anim)
	$AnimationPlayer.play("Armature|mixamocom|Layer0")


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	if !$AnimationPlayer.is_playing():
		var pos = $Armature.get_global_translation()
		var new_pos = Vector3(pos.x, pos.y, pos.z + step_distance)
		$Armature.set_global_translation(new_pos)
		$AnimationPlayer.play("Armature|mixamocom|Layer0")

@acs
Copy link
Contributor Author

acs commented Oct 15, 2022

Ok, my last approach is using the Mixamo animation in place (no displacement) and using this code:

extends Node3D

const step_distance = 0.015

func _ready():
	$AnimationPlayer.play('Armature|mixamocom|Layer0') # Replace with function body.

func _process(delta):
	var pos = $Armature.get_global_position()
	var new_pos = Vector3(pos.x, pos.y, pos.z + step_distance)
	$Armature.set_position(new_pos)

func _on_animation_player_animation_finished(anim_name):
	$AnimationPlayer.play("Armature|mixamocom|Layer0")

@acs
Copy link
Contributor Author

acs commented Nov 16, 2022

Ok, the goal of this task is to have this character, but created from scratch and rigging and animated later by us. So we can show the full process. Using the Mixamo model is cool for a quick demo and for playing with the animation in Godot. It is time to do the same with our own model. Go go!

But this will be done in #69 so it is time to close this ticket!

@acs acs closed this as completed Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant