• News

• Industries

• Learning & Support

• Community

• Marketplace

Vector HOW-TOs - Share what you know!

Hey guys,

I recently started playing around in Unreal and obviously been hit with the realization of having to do VECTOR MATH! Also Rotations They’re scary but fun!

Not everyone is good at math , let alone vectors, myself included. In the past couple weeks there has been a lot of googling, it sucks, and you don’t always find the right answers. So I thought it would be good to pool some HOW-TOs for Vectors and Rotations into a thread where newcomers could quickly figure out what a vector/rotation is and what they can do with them. Possibly we could even share some example uses for vectors and rotations. I will start off by sharing how to calculate how fast you are going, something I am sure many people may find useful.

HOW TO - Figure out your characters velocity in world space, local space and speed in Kilometres per hour(KM/H) (How fast are you moving)

Note. Instead of Event Begin Play and a Delay, you can just use Event Tick to a print string

1. World space velocity is your units per second in World(Map) X,Y,Z. If your character has a max walk speed of 1000 and you are walking along the World X-Axis, your vector would be (1000,0,0) or (-1000,0,0) if going the opposite direction. World Y would be (0,1000,0) and (0,-1000,0). Jumping, falling, walking up or down a hill is Z/-Z velocity (0,0,750).

2. This is your characters Units per second velocity rotated into back into Local Space X,Y,Z. When you’re in your character’s blueprint goto the viewport tab. At the bottom left corner you will see X,Y,Z and your character is most likely has an arrow facing forward along X, this is Local Space and important to understand. By using this velocity calculation, the direction your character is pointing and moving will be always be displayed along X, strafing will display along Y. Projectiles use local space too, the velocity of a standard projectile is assigned to the forward X-Axis. More on this later.

3. UE4 units are in centimetres 1u = 1cm and velocity is units per sec on a given axis. Vector Length gives you the Square Root of (x²+y²+z²) as a float in Units Per Second. Units Per Second is helpful but not really what I want to know, I want to know how fast my character is going in a number that I can easily understand. 1cm/s is equal to 0.036 km/h, which is why we multiplied our vector length.

HOW TO - Impart Projectile Velocity Inheritance (Ever play TRIBES?)

TRIBES was famous for its movement and weapon physics. The gameplay was unique and players were rewarded for their ability to not only LEAD a target but also calculate in their inheritance while moving as well. The disc launcher in vanilla TRIBES had 75% projectile inheritance but was later nerfed to 50%, the chaingun has 100%. What is projectile inheritance?

Projectile Inheritance is the VECTOR SUM of your characters velocity and a projectiles muzzle velocity. (huh?) In real people speak that means the faster you are moving, the faster your projectile will go.(wait, what?)

Again, projectiles use local space X for their velocity. A projectile with 6500 base muzzle velocity moves 6500 units per second along the Local X axis (6500,0,0). When you fire in the world though, the game calculates what direction you are facing and converts it into a World Space Velocity which might look more like (500,5500, -500)<–probably wrong, just saiyan.

This is where #2 comes in above. I want to get my characters local space velocity, store it in a variable and add it to my projectile. See the screenshot below.

In my character blueprint I have set up to capture my current local space velocity as a variable called “Inheritance” just before the projectile spawns. I then right-clicked the Return Value on SpawnActor FirstPersonProjectile and promoted it to a variable called “FPProjectile” (This gives us access to its blueprint components). I then pulled out a Set Velocity in Local Space which overrides the projectiles blueprint velocity.

Again, Inheritance is the Vector SUM of a characters velocity and the base muzzle velocity (Vector+Vector). I set up a simple Math Expression of Inheritance*1, or 100% inheritance (50% is 0.5) and fed that into a Vector+Vector. I then input my desired base muzzle velocity into the X portion and returned the value to the New velocity in “Set Velocity in Local Space”.

Note, it is also important that your Initial and Max Speed are set to 0 (no limit) in the projectile blueprint.

Here are some video of this simple blueprint change in action. Don’t mind the assets :).

At 0% Inheritance, where your crosshair is when you fire, no matter how fast you are moving, that is where your projectile will hit. This is fine if you aren’t moving very fast but this also means that if you fire while moving near or faster than your base muzzle velocity(6500 or 240KM/H in my case) it is possible to run into or out pace your own projectile.

50% is what TRIBES Ascend and Vanilla TRIBES use on their disc launchers(Blinksfusor is 100%). Even though I am firing at the boxes(my aim is bad), my shots are curving to the right or left depending on what way I was moving. I had to calculate where and when to fire to have my shot hit the box. Also, because it is inheriting 50% of my velocity I do not out pace it until I hit well over 400 KM/H. These speeds are possible in TRIBES Ascend but normally only when doing flag runs.

100% is insanely hard to use but that is the challenge. In the 2nd video I set up my base character speed and muzzle velocity to be the same, 1000 units per second. So, if I move backwards at (-1000,0,0) and fire my projectile at (1000,0,0) they cancel each other out and it floats in mid air! Just think of the potential!

0%, 50% and 100% velocity in a “real world” scenario

What can happen when your Base movement speed is equal to your muzzle velocity