3D turrets

Blitz3D Forums/Blitz3D Programming/3D turrets

Defoc8(Posted 2004) [#1]
Ive created a few variations on this..but there are always
problems..taking advantage of the hierarchy system within
blitz makes things much...but there are many problems..
Sure if you fix your turret so that it is basically 2d, its
Y axis being equal to World Y...but as soon as you allow
full 360 orientation..rotations invert..yadda..
Another problem is the Arc-Lim idea..limiting the amount
by which a turret a rotate...

Ive mad cludgey versions in the past..but i was wondering
if someone had any elegant versions?

Anyway..im of to play with some crossproduct ideas....

cheers! ;)
Matt....


Rob Farley(Posted 2004) [#2]
Use this function:

Function AngleDifference#(angle1#,angle2#) 
; Finds the difference between two angles fron -180 to 180
;
; Returns the difference.
Return ((angle2 - angle1) Mod 360 + 540) Mod 360 - 180 
End Function
Then you can find out where it's pointing by using
angle# = angledifference(entityyaw(gun),30) ; where 30 is the direction you want it to be pointing at rest.
This will return -180 to 180 reletive to the resting direction.

You can deal with everything else nice and easily from there.


Zethrax(Posted 2004) [#3]
You'll need to be a bit more specific about the problems you're having.

Using Blitz3D's parent-child entity relationships should allow you to set up turrets effectively.

As far as limiting the degree of arc, just check to see if the entity has exceeded the maximum degree of arc and move it back to the maximum rotation allowed. You will possibly need to store the rotation value in variables, which are updated by the amount of rotation added or subtracted, as some of Blitz's functions to return the current rotation return fairly useless values.

Here's some code I use to set up a user entity with a camera parented to it, which is designed to work in a similar fashion to a turret.



This code allows the above entity to 'mouselook', with the pitch rotation of the camera limited to 180 degrees. (Note: Variables that start with 'the_' are locals.)




Defoc8(Posted 2004) [#4]
ok, cheers! guys..i will try this stuff out l8r ;)
...