Vector3.WithAimCone

Started by garry 4 posts 1,054 views

Reply on sbox.game
  1. #1
    garry Facepunch 2,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. #2
    somewhere_in_universe 2,700
    cool
  3. #3
    Unknown
  4. #4
    Unknown