C++ Changing same variable

Why not show MyVector.Y += 1;? This is the normal C++ convention for changing an existing variable.

I don’t man , I just did SetActorLocation(GetActorLocation()+ FVector(0,5,0));
Because why the hell would I want to cache that vector if I’m not going to reuse it?
You could do an If statement later and reuse it but I guess that requires me to interact with the player actor anyways and then ill get its location.

As long as there is no factor in it for speed (or adjusting to varying FPS rates between different machines or machine load), one could as well just use

MyVector.Y++;

:wink:

This is assuming y is the direction you wish to go in, say forward for example. This is why you use Get Forward Vector which will guarantee your actor moves in the forward direction of your actor and it is a unit vector.

The reason is that it takes into account any rotation so will give you a unit vector pointing the correct direction.

If you want to factor for speed and the delta time, just multiply. You should do this anyway to account for varying framerates.

All of it is assuming you want to move in Y direction at this point.

Specifically testing which way is “forward” and using some movement vector for going more than one direction and at different speeds is stuff that will be covered in upcoming lessons. :wink:

Privacy & Terms