Download

Movement... crouch, prone, etc...

I followed one of the C++ tutorials to set up movements (forward, jump, etc) and all that works. I understand binding axis and actions to a function such as move and how that works. For jump you are just setting bPressedJump to true or false. Where is that read/used? It appears somehow that sets ‘Falling’ in the Enum which triggers the character to jump. But not sure… anyway, now I am trying to figure out how to add things like crouch and prone with C++. I can bind the key command to a function, but not too sure what to set… I can make a variable to set if crouched is pressed or not, but that passes back to the character BP, not the animation BP. Am searching documentation and such, but not seeing the needed connection that I am missing.

Thanks

Sad that nobody knows.

In the Character Movement Component. There is a function called perform movement, which is called every tick. In there it handles movement, etc. One of the things it does in regard of jumping is checking if the character wants to jump (that is related to bPressedJump) and performs the jump if necessary. If I remember right it calls the DoJump function of the character or of the MovementComponent. This function just adds Velocity in Z direction and sets the MovementMode to Falling, so that gravity will be applied to the characters Movement.

Well its a bit of a short discribtion of what’s going on. Look at the code of the CharacterMovementComponent. Important functions would be TickComponent, PerformMovement, PhysWalking, PhysFalling and the stuff related to jumping.

Crouch is also already implemented for characters. If you search for crouch you will find the implementations inside the Character and CharacterMovementComponent source code.
Prone would need to be implemented by you. You can probably do it similarly to crouching, but depending on how you want the Prone Collision to be, you might have to do quite a lot of programming for a Prone Movement Mode, because the Character Movement Component is mostly made for capsule collision.

Thanks…

I too was looking for how to pass variables to the animation blueprint, but I can’t find it anywhere…

If you want to know how to get curves and notifies, I’ve figured it out here:
https://answers.unrealengine.com/answers/301155/post.html

@Tomura
You think the CharacterMovementComponent will show how to send variables to the anim blueprint? I tried looking for that class but couldn’t find it in visual studios. Lots of odd versions of it, but not the actual class.

I’ll split this post up in two parts, logic and animation, to try to help you both arbopa and Juice-Tin.

arbopa:
For implementing jumping and crouching in C++, CharacterMovementComponent has this already built-in and customizable, link to documentation. For example it has functions Jump(), Crouch() and UnCrouch(), IsMovingOnGround(), IsCrouching() etc prepared. Jump will give you upward velocity as you would expect, and you can tweak the strength by setting the CharacterMovementComponent’s JumpZVelocity value. Similarly crouch/uncrouch toggles your character’s collision capsule height (your camera will be lower since it’s a child of the capsule) and max movement speed. Again it has properties so you can adjust what those heights are. Be sure to check out the documentation and check the character movement component in blueprints, using blueprint here will help you explore the features.

Proning is not supported by CharacterMovementComponent, but you could use crouching for this with different values, for example:

  • When crouching, set the CharacterMovementComponent to crouching height A, max speed A and call Crouch()
  • When proning, set the CharacterMovementComponent to crouching height B (lower), max speed B (again lower) and call Crouch()

Juice-Tin:
As for passing variables to the animation blueprint, you have to realize that an animation blueprint has two graphs, the anim graph and the event graph, with shared variables. In the event graph there is an “animation update” event node that fires every frame that allows you to update your animation variables. You can for example create booleans IsJumping, IsCrouching, IsProning in your anim BP, set them in the event graph and then read them in the anim graph. Your event graph can simply try to cast the anim BP’s controlled to a character and then call the character movement component’s IsMovingOnGround() and IsCrouching() functions. To differentiate between crouching and proning, you’ll need to store whether you are proning in your character class and then read it.

Oh, sorry. Seems like I didn’t read that post properly. I was expecting that the question was about the MovementComponent logic, because it’s not very well documented (last time I checked) and there often are questions about that. My bad.

Seems like NisshokuZK has answered the animation part.

Sorry I meant for accessing those variables from C++, which I’ve figured out below.

To pass variables from C++ to the Animation Blueprint, look here:
https://answers.unrealengine.com/questions/301155/get-blueprint-animation-variables-in-c.html

I went with the first option he suggested. Extend the AnimInstance class, put your public variables in there. Then Reparent your animation BP and you will see your C++ variables on the animation BP. You can use those between code and BP very nicely.