Vector3.WithAimCone

Started by garry · one year ago · 3 replies · 1,057 views

#1
garry
Facepunch
JoinedApr 2021 Posts436 Score2,270
This extension will add random aim code to a Vector3 direction.

public static class Extensions
{
	public static Vector3 WithAimCone( this Vector3 direction, float degrees )
	{
		var angle = Rotation.LookAt( direction );
		angle *= new Angles( Game.Random.Float( -degrees / 2.0f, degrees / 2.0f ), Game.Random.Float( -degrees / 2.0f, degrees / 2.0f ), 0 );
		return angle.Forward;
	}

	public static Vector3 WithAimCone( this Vector3 direction, float horizontalDegrees, float verticalDegrees )
	{
		var angle = Rotation.LookAt( direction );
		angle *= new Angles( Game.Random.Float( -verticalDegrees / 2.0f, verticalDegrees / 2.0f ), Game.Random.Float( -horizontalDegrees / 2.0f, horizontalDegrees / 2.0f ), 0 );
		return angle.Forward;
	}
}
#2
somewhere_in_universe
Member
JoinedJan 2024 Posts43 Score2,700
cool
delete
Deleted Post
delete
Deleted Post
people
Log in to reply
You can't reply if you're not logged in. That would be crazy.