This is very cool, I like how the hud moves when the player moves but how is something like this done?
Well, I do a similar thing with my HUD- here’s my code - the part you’ll be looking for is under walk movement
One of my update videos with gameplay in it (just skip to about 20 seconds in)
Basically, I just took the distance moved and plugged it into a Cosine equation.
squared55 the guns in your game take up to 1/3 space of the screen. But I like the movement, very fuild.
I cant figure it out Is there a simpler way? Like making it move when move when w is pressed and it moves a little faster when w and shift are held down?
You could set up animations that offset/move the hud when walking / jumping / ect it would not work perfectly but would provide the basic feel your after.
Let me try explaining a little better. Remember this from highschool?
Notice how the higher the x-value gets, the y value alternates between 1 and -1? Well, if you have a maximum sway value, simply multiply the value by the result of the cosine function, and then add the result to the x or y position of the HUD.
In other words:
//distance moved since the start of the game
var totalDistanceMoved : float;
//Self Explanatory
var positionLastFrame : Vector3;
//Speed at which the HUD sways
var swaySpeed : float;
//maximum amount to move HUD
var maxMovementValue : float;
//Self Explanatory
var numberToAddToGUICoordinate : float;
function Update()
{
//Get the distance moved since last frame
totalDistanceMoved += Vector3.Distance(transform.position, positionLastFrame) * Time.deltaTime;
//Get the amount to add to the GUI's x or y coordinate
numberToAddToGUICoordinate = Mathf.Cos(totalDistanceMoved * swaySpeed) * maxMovementValue;
//Get position this frame to compare next frame
positionLastFrame = transform.position;
}
Still in high school thanks now its clear