Using mouse position to control character animation - unreal-engine4

I would like to set up an animation for my character and have the progression through the animation be controlled by the mouse movement.
E.g. the character starts in a rest state - the first frame of the animation - as the mouse moves through the x axis, it plays the animation forward in a linear relationship with the movement of the mouse. If you stop, the animation halts at that point and if you move backwards, the animation is reversed.
Like scrubbing in a video editor except instead of a vide, it's a character animation.
I'm guessing this is eminently doable but will it be relatively trivial to do within Blueprints or am I better off using C++?

SquidInker!
I'm two years late here, but for the sake of Google posterity here is the Blueprint solution as of engine 4.17.0:
In your Animation Blueprint, right-click on the node for the animation asset in question, and select "convert to single frame animation"
Your node will now have an "explicit time" input pin, which you can parameterize as you like to scrub through your animation:

Related

The turret of tank can not be turn towards the player pawn? where is the problem?

I have a simple game done using unreal engine 4,
The turret of the tank should turn toward the player pawn.
I made the blueprints code to build that, but the turret rotates quickly and incorrectly.
Video about problem
I tried to solve the problem many times without any results !!
Hope to help me.
There are probably a few ways you can do this, but you can simplify this quite a bit. I also suspect you can do all of it in the animation blueprint.
Simplify the first part (XDoMa.jpg) using the Find Look At Rotation node.
Break the output of this and create another rotator with the yaw from that node and the pitch and roll from the turret's world rotation (you're currently setting pitch and roll to zero in cDJ08.jpg, which you don't want to do in case the tank is on a slope).
To rotate the turret to point at the target, use the RInterp To node and connect its output rotator to a Set World Rotation node. The nice thing about the 'RInterp To' node is that you can set the speed. For a bit more realism you could use some simple maths to accelerate and decelerate the turret's rotation.
Another thing you'll want is a bool variable in the tank actor BP. Then you can use a branch in the animation BP to trigger the stuff above when you set the bool to true.
The key parts to this are the Find Look At Rotation and RInterp To nodes, and to do all of it in the animation BP.

How to use Projectile Movement to make my Character jump?

I have a brand new blueprint derived from the Character class, and I've added a Projectile Movement Component onto it. I'm having trouble making the character Jump.
The reason why I want to do this is I want to use the projectile movements bounce physics while my Character is in the air, but while they are on the ground use the Character Movement Component to move.
If I set the initial speed of the Projectile Component I can spawn with some forward momentum. However if I try to bind any kind of force or change in velocity to some user input - my character refuses to leave the ground!
My blueprint: https://imgur.com/a/UBuzcq3
When I spawn in the game world, I can see "Jumping" displaying properly but I do not move:
https://imgur.com/a/rGXX3gG
Can someone help me understand why this is happening and how to fix it? I'm fine with C++ solutions as well (I've also tried AddForce function in C++ but have the same problem!)
I have noticed that if I tick "Rotation Follows Velocity" in the Projectile Component then I do get some movement but its super weird and jerky and not at all useable.

Unreal Engine 4 - Add offset to character movement

I just started (yesterday) using unreal engine and I need to simulate a drunk character using BPs.
I'm using two camera shakes (one for standing still and one for walking) but I want to add some "displacement" on charater when he's walking.
Basically I want to define a random float to be added to X axis location in order to make character wobble smoothly.
It will be acceptable even if there's a way to make the character move along with the camera when it's shaking.
What I tried until now is using AddActorLocalOffset and a timeline to lerp between actor's location and actor's location+offset, but both are very choppy to me.
Maybe it's a noob question but as I told I'm very new to this and need it for a quick work.
Any suggestion?
Thanks
If you are targetting physically correct model, you should use AddForce (UE Docs). But this approach would require implementation of a "drunk animation" where your character will modify it's movement animation to "compensate" this force by stepping aside etc.
Another (much more simple) approach is by using AddMovementInput. This example can be seen here: UE Aswers. In this case, you are basically simulate player's input by adding small amount of side force here and there.

SpriteKit move node with physics rather than updating position

My main character moves by touching and holding him and then moving your finger left or right to move the character. To do this I just simply update the node's x position (walks left and right on a flat surface) in touchesMoved() with the x position of the touch location, and apply an animation depending on the direction he's moving.
I want to kind of take this to the next level and accomplish the same effect, but using physics, so that when I'm done moving him and release my finger, he may slide a little bit in the direction he was moving given the speed I was moving him at, if that makes sense. Does anyone know how I can accomplish this effect?
Would I have to do as I'm currently doing and update the position as it moves, but also apply a force/impulse at the same time? Kind of confused on how to approach this
Moving the physics body via force, impulse, or velocity will automatically update the player position.
So you will have to play around with the correct way to accomplish your goal. But based on this, what I would suggest is replace your .position code with .physicsBody!.velocity code in your touchesMoved. Then, on your touchesEnded, you can apply a bit of an impulse to give the player that little bit of an "on ice" effect to keep them going a tad.
You will need to experiment with how much velocity you want to get the character to move at the correct speed, and then you will need to play with the impulse figures as well to get it just right.
This could get a bit tricky though, in touchesMoved... because at some point you will want to reset the velocity to 0 (so they stop moving when your finger stops).
To do that, you will need to to use the .previousLocation from your touch object, and compare the distance of X moved. if the distance X moved is >0 (or some deadzone threshold) then apply the velocity; if the deltaX is 0, then set the velocity to 0.
This may actually be more complicated than just using .position to move the character, then having the character slide a bit with physics on touchesEnded.
You will have to play with it to get it right.

Need Unity character controller to make sharp 90 degree turns and not slide when turning

I'm using the first person controller for my characters movement. On a left arrow keypress, I'd like the character to instantly rotate 90 degrees and keep moving forward. Currently, when I hit the arrow key, the character makes the sharp 90 degree turn, but the forward momentum the character previously had takes a second to wear off so the character ends up sliding in the direction he was previously moving a short bit.
The closest example I can think of to visually explain what I'm trying to do is how the character turns sharp in Temple Run. How my game is currently working, if I had the character on a ledge make a sharp left turn, he'd likely keep the original momentum and slide off the edge right after he turns.
Since my character is running on the x/z axis, I'm wondering if there would just be some way to maybe swap the directional velocity/momentum? The speed the character had on the x axis would instantly be switched to the z when it turns and the other would be set to zero. I'm obviously open to any solution that accomplishes what I'm looking for.
I dug into the CharacterMotor class in the first person controller, but have yet to find what part I can tweak to accomplish this.
I'd greatly appreciate any help.
Thank you.
You can try to stop the velocity of the Rigidbody before turning.
this.rigidbody.velocity = Vector3.zero;
this.rigidbody.angularVelocity = Vector3.zero;
If you want the object to continue like it did, you can try playing around with it by saving the current velocity in a variable, setting it to 0, rotate it and then putting back the old velocity (still forward).
If it works with global vectors (so from the point of view of the world, not the object), then you can try negativing the velocity, actually causing it to go 'backwards'. I can't test it for now but either way I think you need to set the velocity to zero first before turning the character.