Home
Products
Community
Manuals
Contact
Login or Signup

Code archives/3D Graphics - Maths/RotateToAngle for BlitzMax

This code has been declared by its author to be Public Domain code.

Download source code

RotateToAngle for BlitzMax by Weijtenburg(Posted 1+ years ago)
This function allows you to rotate towards an object at a given speed. I tried adding a gradual setting, but i beleive i theirfore need to have the old angle stored, however, i got lost trying...
Function RotateToAngle:Float(srcangle:Float, destangle:Float, speed:Float = 1, gradual:Int = 0) 
	Local angle:Float = srcangle - destangle
	If gradual 'WORK IN PROGRESS
		Return angle + speed 'doesnt work properly
	Else
		If angle > 180
			angle:-360
		Else If angle < - 180
			angle:+360
		End If
		Return angle * speed
	End If
End Function

Comments

Altanil(Posted 1+ years ago)
I don't really understand the use of this. Could you post an example?


Weijtenburg(Posted 1+ years ago)
i cant post an example. but i can explain it to you. assume you have a target (the player) and a turret. Using the function GetAngle (http://www.blitzbasic.com/codearcs/codearcs.php?code=2212) you get the angle for the turet to the player. If you would update the angle of the turret just like that, it would BOOM be in the right angle at once, but you want it to rotate towards the player. So that is where this function comes in. Using RotateToAngle, you specify the current angle of the turren, and the new angle which is returned by GetAngle. The turret will now rotate towards the player by the given speed. 0.01 = slow. 1 = instant. 0.5 = halfspeed.


Altanil(Posted 1+ years ago)
Ah I get it, quite simple but could be usefull.


Twitchfactor(Posted 1+ years ago)
This and the previous "GetAngle" are EXTREMEMLY useful and I was surprised they weren't included in BlitzMax already.

Anyone doing any flocking, spaceships or boats flying towards each other, guided missiles, whatever... this is what you use.

I thank you very much Goldstar for making these.


GW(Posted 1+ years ago)
Has anyone tested this?
I find that it doesn't work.


Code Archives Forum