How to make a character move direction by an exact distance?
Hi I'm planning on making my project a top down game.
Is there a way to press 'W' key to make the character move a specific distance like 100 grid squares and stop?
asked Apr 27 '16 at 06:23 PM in Blueprint Scripting
hey! you did not specify which way you wanted your character to move, i am just assuming that you want him to go the way he faces.
get forward vector always returns a vector with length of 1, so we are getting a vector with length of 1, facing the way our character is facing, multiplying it with say like "100", and adding it to our current location
answered Aug 28 '16 at 08:49 PM
You can use the movement component, or the navmesh and a couple of other things. Using some of these you just need to give him the location where you want to go. Lets keep it simple, but keep in mind that the way you choose to manage the movements is really important.
For now, lets use my favorite way. Simple actor with custom blueprint. If you have an actor and want to move it of some meters in a direction , you have to.
Give the actor a variable like a vector , to use as target. you have to put on a system to make all gradually so.... Make the actor turn to look at the right direction. you can calculate the rotation using "find look at rotation" node. Now use the node "LerpR " to transform , your rotation , in the desired rotation..... Now you can use ""Set actor rotation"" , doing this you will have an actor turn to the location .
once your actor in looking the right direction you can start moving. Its quite simple if you have the location. just set the world location of your actor , this way. Get your actor location:add a vector (Vector forward). this will move the actor on forward of 1unit. You can multiply the vector by a Speed value, like 5 , to make it move at 5 unit per time. The very last thing is create an ""IF"" , before move, you want to check how much close to the location you are. So take the location of the actor - subtract the desired location and use the node , lenght vector. if this value is lower than 0.1 , you are there. To fix perfectly you can teleport in the exact location , and we are done. hope its clear
answered Apr 30 '16 at 11:35 AM
Few days back I was also trying to achieve the same thing. You can go through this post: How to move my charater for specific distance just single key press? https://forums.unrealengine.com/showthread.php?117815-How-to-move-my-charater-for-specific-distance-just-single-key-press
Hope it helps.
Follow this question
Once you sign in you will be able to subscribe for any updates here