AnimationPlayer adjust CollisionShape/Camera position (First person camera)

Godot Version

4.2.1.stable

Question

I’m working on a multiplayer FPS shooter with first person camera. The character is from mixamo and the animations too (idle, walking, jumping, running, crouching, …).
The character currently has a CapsuleShape3D as CollisionShape3D - I might change that later, not sure yet.

When going into crouching, the character has a smaller height and therefore I’d like to reduce the CapsuleShape3D’s height and position as well as the Camera3D’s position.

I figured I could do it via the AnimationPlayer - adding a Key for those properties I want to adjust. However, when I do this, the initial Camera3D and CollisionShape3D position is wrong when starting the game.
For example: In the editor the Camera3D position.y is at 1.7m. When I print it during _physics_process() (with the AnimationPlayer Crouching having a track for Camera3D position setting to 1.4m), the position is reported as 0.

I assume the reason is because in my other animations (e.g. Idle), I don’t have a track for the Camera3D position. To fix this I’d need to set the position on every animation which is a little cumbersome.

Is there a better option or am I doing something wrong?

Another option I thought would be to add another bone to each animation and attach the Camera to that bone (so it doesn’t shake like e.g. the Head does). I’m not sure if that’s a good approach though.

Thank you!

Check if the AnimationPlayer has a RESET animation and if the values of the tracks are correct in that animation.

To not having to add tracks to all animations in your model’s AnimationPlayer you could create another AnimationPlayer and animate the Camera3D.position and CapsuleShape3D.height and CapsuleShape3D.position in it independently of the model’s AnimationPlayer.

1 Like

Thank you for your reply!

Check if the AnimationPlayer has a RESET animation and if the values of the tracks are correct in that animation.

Yes it has a RESET animation and there are tracks for the properties for both CollisionShape3D and Camera3D. However it seems it’s not applied when running a different animation or when first starting another animation and then running the crouch animation. Could that somehow be enforced?

To not having to add tracks to all animations in your model’s AnimationPlayer you could create another AnimationPlayer and animate the Camera3D.position and CapsuleShape3D.height and CapsuleShape3D.position in it independently of the model’s AnimationPlayer.

Ah, that’s a good idea I didn’t come up with! Thank you, will try that.

The RESET animation is an special animation that will be applied when saving when AnimationMixer.reset_on_save is true (the default value) It does not get applied between animations.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.