I'm having a little problem with some programming. The language I choose to use only offers the option to set a destination of where an object starts and ends according to coordinates of the map. (Which is 3D).
I know that the object being created will start at where the player is, and I know how far it will travel. What I dont know, is how to work out where it will end.
The function im uses syntax like:
CreatePath( StartX, StartY, StartZ, NewX, NewY, NewZ )
All I need to know, is the formula that can be used in NewX, NewY and NewZ.
(Which will change as the user rotates and moves)
I have tried playing around with Cos and Sin, but I really dont understand what is going on with it.
If anyone understand the problem and could explain it, please do.
I will be happy to explain further the problem I'm having and answer any questions as its rather important for my learning.
Thanks for reading.
If you can clarify the type of information you have, I can probably help. What you are dealing with is converting either cylindrical or spherical coordinates to XYZ coordinates. If you tell me what you do know about the motion I can give you the conversion formulas.
Well, the reason I ask is because I am very new to the whole 3D creation programming. While I was waiting for a reply, I managed to find some helpful information.
On another website found by google, I saw this:
snglookatX = sngPositionX + Cos(sngAngleY)
snglookatY = sngPositionY + Tan(sngAngleX)
snglookatZ = sngPositionZ + Sin(sngAngleY)
Somebody called 'zork' used this for 3D movement. I quickly adjusted his idea to work in my project and now I have some slight progress. The objects, or bullets rather, being created are flying a certain distance in a circle shape, but are not exactly... accurate. There seems to be some more problems with my code that I first realised.
Here is the syntax of the function im using:
ObjectPath( StartX, StartY, StartZ, EndX, EndY, EndZ, Time, Loop )
...and here is my code:
If you need anymore information, just ask.Code:ObjectPath(GetPosition($Camera, "X"), GetPosition($Camera, "Y"), GetPosition($Camera, "Z"), GetPosition($Camera, "X") + Cos(GetRotation($Camera,"Y"))*200, GetPosition($Camera, "Y") + Tan(GetRotation($Camera,"X")), GetPosition($Camera, "Z") + Sin(GetRotation($Camera,"Y"))*200, 1000, 0 )
Edit: Think of this as just any old FPS... firing bullets from a character to a certain distance.
Here's the main question: are you looking at things from the perspective of rotation, angle of ascent, range, or from rotation, elevation, range? I'm guessing the first.
If the first, when viewed from overhead consider right/east/positive x-axis as 0 radians (not degrees!) and rotate counter-clockwise (2pi = 360 degrees). The limit of your shot is then at point:
shotX = cameraX + range*cos(rotation)*cos(angleAscent)
shotY = cameraY + range*sin(rotation)*cos(angleAscent)
shotZ = cameraZ + range*sin(angleAscent)
To convert between radians and degrees:
radians = pi*degrees/180;
degrees = radians*180/pi;
The directions you got were just wrong.
Thank you very much for this information, although I havent used it in my program yet, it will surely be of great use.
Sorry for not replying sooner, I was unable to get on the internet for a while since.
Again, thanks very much. Greatly appreciated.
*Goes to play with code*
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks