# IrrLicht / 3D Geometry confusion

## Recommended Posts

Below is the link to help understand the problem I am having:

You will notice that when a bullet is fired, it seems like it fires in a random direction. It does not fire towards the centre of the screen at all.

However, these bullets are not being fired randomly, from the video you can see that they are infact being fired in a spherical range pre-determined around the character, depending on thier position. Also, you will see that when I move the mouse just slightly, the direction of the bullet eminently changes in relation to the players rotation.

I have been to several math forums asking for explanations or formulas that could help me with this, but they dont seem to work.

Here is the code I am using for this part of the program:

```\$NewX   =   (GetPosition(\$Camera, "X")  + \$Distance * Cos(GetRotation(\$Camera,"X")) * Cos(GetRotation(\$Camera,"Y")))
\$NewY   =   (GetPosition(\$Camera, "Y")  + \$Distance * Sin(GetRotation(\$Camera,"X")) * Cos(GetRotation(\$Camera,"Y")))
\$NewZ   =   (GetPosition(\$Camera, "Z")  + \$Distance * Sin(GetRotation(\$Camera,"Y")))
\$ShotAnimator = CreateFlyStraightAnimator(GetPosition(\$Camera, "X"), GetPosition(\$Camera, "Y"), GetPosition(\$Camera, "Z"), \$NewX, \$NewY, \$NewZ, 2500, 0 )                                ;Thanks to WingedPanther @ CodeCall```

If you have any ideas about how to fix this, please try to explain it rather than just post the answer, thanks for taking an interest in my problem. Oh, and if you need any more information just ask.

Still learning...I love autoit. :)

##### Share on other sites

Below is the link to help understand the problem I am having:

You will notice that when a bullet is fired, it seems like it fires in a random direction. It does not fire towards the centre of the screen at all.

However, these bullets are not being fired randomly, from the video you can see that they are infact being fired in a spherical range pre-determined around the character, depending on thier position. Also, you will see that when I move the mouse just slightly, the direction of the bullet eminently changes in relation to the players rotation.

I have been to several math forums asking for explanations or formulas that could help me with this, but they dont seem to work.

Here is the code I am using for this part of the program:

```\$NewX   =   (GetPosition(\$Camera, "X")  + \$Distance * Cos(GetRotation(\$Camera,"X")) * Cos(GetRotation(\$Camera,"Y")))
\$NewY   =   (GetPosition(\$Camera, "Y")  + \$Distance * Sin(GetRotation(\$Camera,"X")) * Cos(GetRotation(\$Camera,"Y")))
\$NewZ   =   (GetPosition(\$Camera, "Z")  + \$Distance * Sin(GetRotation(\$Camera,"Y")))
\$ShotAnimator = CreateFlyStraightAnimator(GetPosition(\$Camera, "X"), GetPosition(\$Camera, "Y"), GetPosition(\$Camera, "Z"), \$NewX, \$NewY, \$NewZ, 2500, 0 )                                ;Thanks to WingedPanther @ CodeCall```

If you have any ideas about how to fix this, please try to explain it rather than just post the answer, thanks for taking an interest in my problem. Oh, and if you need any more information just ask.

first you need convert your angle to radians to use autoit "cos" function. Something like: Cos( (2*\$PI/360) * GetRotation(\$Camera,"X") )

Só o que posso lhe dizer, bom é quando faz mal!My work:Au3Irrlicht - Irrlicht for AutoItMsAgentLib - An UDF for MSAgentAu3GlPlugin T2 - A 3D plugin for AutoIt...OpenGl Plugin - The old version of Au3GlPlugin.MAC Address Changer - Changes the MAC AddressItCopter - A dragonfly R/C helicopter simulator[center] VW Bug user[/center]Pinheiral (Pinewood) city: http://pt.wikipedia.org/wiki/Pinheiral

##### Share on other sites

In Math.au3 there is a function called _Radian(\$Degrees) which does the conversion, too

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

##### Share on other sites

```\$NewX   =  ( \$StartX + \$Distance * (Cos(_Radian(Mod(GetRotation(\$Camera,"X"),360))) * Cos(_Radian(Mod(GetRotation(\$Camera,"Y"),360)))))
\$NewZ   =  ( \$StartZ + \$Distance * (Sin(_Radian(Mod(GetRotation(\$Camera,"Y"),360)))))```

Thank you both very much.

Thats certainly progress, its not so sensitive now, however it seems that the angles are being inverted or something...

When firing a bullet at 270 radius, it will fly off towards 180... but! If I fire a bullet at 180, it doesnt go left again. Instead it goes back to the right, to 270.

The same happens when trying this with 180 and 90.

If I shoot facing 90, it goes towards 180. From 180, goes off to 90.

I'm sure there is a simple fix for it, but I know now that it isn't setting the raduis to be deducted from a preset value. =/

If you feel like helping me out again, go ahead. If not, thanks anyway for helping me so far.

Edited by disc330

Still learning...I love autoit. :)

##### Share on other sites

```\$NewX   =  ( \$StartX + \$Distance * (Cos(_Radian(Mod(GetRotation(\$Camera,"X"),360))) * Cos(_Radian(Mod(GetRotation(\$Camera,"Y"),360)))))
\$NewZ   =  ( \$StartZ + \$Distance * (Sin(_Radian(Mod(GetRotation(\$Camera,"Y"),360)))))```

Thank you both very much.

Thats certainly progress, its not so sensitive now, however it seems that the angles are being inverted or something...

When firing a bullet at 270 radius, it will fly off towards 180... but! If I fire a bullet at 180, it doesnt go left again. Instead it goes back to the right, to 270.

The same happens when trying this with 180 and 90.

If I shoot facing 90, it goes towards 180. From 180, goes off to 90.

I'm sure there is a simple fix for it, but I know now that it isn't setting the raduis to be deducted from a preset value. =/

If you feel like helping me out again, go ahead. If not, thanks anyway for helping me so far.

Yes! Sum 90 to angle. Cos( (2*\$PI/360) * ( GetRotation(\$Camera,"Y") + 90 ) )

Só o que posso lhe dizer, bom é quando faz mal!My work:Au3Irrlicht - Irrlicht for AutoItMsAgentLib - An UDF for MSAgentAu3GlPlugin T2 - A 3D plugin for AutoIt...OpenGl Plugin - The old version of Au3GlPlugin.MAC Address Changer - Changes the MAC AddressItCopter - A dragonfly R/C helicopter simulator[center] VW Bug user[/center]Pinheiral (Pinewood) city: http://pt.wikipedia.org/wiki/Pinheiral

## Create an account

Register a new account