Download

Weapon Sway (CSGO/COD STYLE)

Is there an algorithm to add weapon sway like in most fps games like for example csgo? I been lookin everywhere can’t find in unreal. I was mainly trying to implement this in shooter game sample. Here is a link of what I want but in ue4 rather than unity: https://www.google.ca/url?sa=t&rct=j&q=&esrc=s&source=web&cd=5&cad=rja&uact=8&ved=0CDUQtwIwBGoVChMIiv3Rn__5xgIVgaYeCh055ADq&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DmwPIN8Nx3-U&ei=IHO1VYrtJYHNernIg9AO&usg=AFQjCNGa1OOsKFfc83WQ0p2AERbfrTmUMQ&bvm=bv.98717601,d.dmo https://www.google.ca/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&cad=rja&uact=8&ved=0CDIQtwIwA2oVChMIiv3Rn__5xgIVgaYeCh055ADq&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DkDwZJH2whO0&ei=IHO1VYrtJYHNernIg9AO&usg=AFQjCNHzbZXTDPQROa_jnh-HDC-2tOAE6Q&bvm=bv.98717601,d.dmo .Thanks in advance.

Bump???

You might have better luck in the animation/blueprint sub-forums. I’m not sure there is an easy method through C++.

My first port of call would be a timeline in blueprint, its easy to set up a curve to drive your weapon position over a set time.

Doing it in C++ is a little clunkier. You can create the VectorCurve in the editor and reference it in code.
There’s an implementation of timelines in c++ in this answerhub page:
https://answers.unrealengine.com/questions/115830/why-is-timeline-bindufunction-only-called-once.html

Hopefully this gets you on the right track.

If you do not need it to be physically correct (as in depend on intertia of the weapon) I have used this piece of code:



InputComponent->BindAxis("Turn", this, &AQuakeCharacter::TurnWeapon);
InputComponent->BindAxis("LookUp", this, &AQuakeCharacter::LookWeapon);

void AQuakeCharacter::TurnWeapon(float Val)
{
	lookVector.X = Val;
}

void AQuakeCharacter::LookWeapon(float Val)
{
	lookVector.Y = Val;
}

//smooth movement of weapon when dragging mouse
	if (lookVector.X != 0.0f)
	{
		float moveX = -lookVector.X * 2.0f;
		PlayerArms->RelativeLocation.Y = FMath::FInterpTo(PlayerArms->RelativeLocation.Y, moveX, DeltaTime, 5.0f);
	}
	else
	{
		PlayerArms->RelativeLocation.Y = FMath::FInterpTo(PlayerArms->RelativeLocation.Y, 0.0f, DeltaTime, 10.0f);
	}

	if (lookVector.Y != 0.0f)
	{
		float moveY = lookVector.Y * 2.0f;
		PlayerArms->RelativeLocation.Z = FMath::FInterpTo(PlayerArms->RelativeLocation.Z, moveY, DeltaTime, 5.0f);
	}
	else
	{
		PlayerArms->RelativeLocation.Z = FMath::FInterpTo(PlayerArms->RelativeLocation.Z, 0.0f, DeltaTime, 10.0f);
	}

It is a bit fragmented since it is pulled from a bigger piece of code but I am sure you can adjust it for your needs. Also, there seems to be a bug that forces you to call UpdateChildTransforms() to actually update the locations of childed scene components when standing still, but it might be fixed by changing all direct changes of the relative locations to using SetRelativeLocation().

You can see it somewhat in action here (just skip past the beginning since that is just me generating levels):

https://youtube.com/watch?v=4KzP9qhGQwo