Game Development Community

Angle scaling

by Christian M Weber · in Torque 2D Beginner · 12/09/2014 (8:04 pm) · 3 replies

So I'm working on my AI and want them to pick points around them to randomly move to.

I have some test code for moving around a point, I'm just wondering if there is a better way to do it.

Circle around point
$updateTester_Angle++;
		if($updateTester_Angle > 360)
			$updateTester_Angle -= 360;
		
		// Get dir vector
		%vec = Vector2Normalize(MatrixMulVector("0 0 0 0 0 1 "@$updateTester_Angle, "0 1 0"));

		%vec = Vector2Scale(%vec, $updateTester_Range);
		%posEnd = Vector2Add(%POS, %vec);
		echo("posEnd ("@%posEnd@")");


Thanks.

#1
12/10/2014 (5:52 am)
I think you've pretty much got it - normalize and scale. You could add an engine-side function that does it but unless you're doing this extremely frequently you probably wouldn't notice the difference in speed.
#2
12/11/2014 (4:18 pm)
I did some digging, found two handy functions!

%angle = Vector2AngleToPoint( %startPOS, %endPOS );
if(%angle < 0)
  %angle += 360;
%NEWendPos = Vector2Add( %startPOS, Vector2Direction( %angle, 10 ) );


Always cool to find stuff within the engine lol.
#3
12/12/2014 (5:54 am)
Nice - cuts down on "thunks".