Gamesnert Posted August 9, 2008 Share Posted August 9, 2008 Since I script for VNRP most of the time now, I now got in touch with gatemoving codes, and made a small GUI for it. But it's not effective, It can only know where to go to if I know it... What I mean is for example if I want a gate to be moved about 4 meters, if I want it to the right, I do x+4 (just to make it easier to understand). To the left x-4, up y+4 down y-4. But how do I let a script calculate where it should end if it's for example rotZ=236 and I want it to be moved 5 coordinates to the right? Then it's X AND Y axis would change... How can I calculate this? Thanks in advance, Gamesnert. Link to comment
Mr.Hankey Posted August 9, 2008 Share Posted August 9, 2008 rot = 76 x = 0 y = 0 distance = 4 newX = math.cos (math.rad(rot))*distance newY = math.sin (math.rad(rot))*distance Additionally you should read a bit on wikipedia about Trigonometry. Link to comment
Gamesnert Posted August 9, 2008 Author Share Posted August 9, 2008 I did, but didn't understand a single thing about it... =/ Anyway, thanks. Going to try it as soon as possible. EDIT: Hmmm... The gates fly away... Maybe because x and y aren't in the calculations? EDIT2: Solved! For opening, I use: local newX = x+math.cos (math.rad(rz))*distance local newY = y+math.sin (math.rad(rz))*distance While closing needs: local newX = x-math.cos (math.rad(rz))*distance local newY = y-math.sin (math.rad(rz))*distance I know for sure I'll get sin, cos and tan the after the holliday or next year in school, so untill then I'll read and try to understand the wiki... *Sigh*... Link to comment
Mr.Hankey Posted August 10, 2008 Share Posted August 10, 2008 oh right i forgot the x+ and y+ before^^ Link to comment
DefiniteIntegral Posted August 11, 2008 Share Posted August 11, 2008 I have a similar query to so I thought this thread would be a good place to post it. I have gotten rusty after several years without using any trigonometry, so I am not really sure what I am doing. I want to find the vector which would result from the transform described by getVehicleRotation. Specifically, I want the vector describing the direction the vehicle is facing, which I guess is obtained from X and Z rotations, ignoring roll. local rx, ry, rz = getVehicleRotation(vehicle) local vx = cos(math.rad(360-rz)) local vy = sin(math.rad(360-rz)) local vz = 0 That is the 2d vector representing direction, right? What should I use to obtain 3d vector? My problem is not knowing how to get correct vx and vy. Should I just get vz based off x rotation then normalize the vector, or can I rotate vx and vy using sin or cos? Link to comment
Mr.Hankey Posted August 11, 2008 Share Posted August 11, 2008 a few month ago i made a kind of spectation script which contained a free-look mode that was using a forumla that might help you function setCameraRotation (rotx, rotz) local x, y, z = getCameraPosition () local x2 = math.sin (math.rad(rotx))*math.cos (math.rad(rotz)) local y2 = math.sin (math.rad(rotx))*math.sin (math.rad(rotz)) local z2 = math.cos (math.rad(rotx)) local result = setCameraLookAt (x+x2, y+y2, z+z2) --outputChatBox (tostring (x+x2*3).." "..tostring (y+y2*3).." "..tostring(z+z2*3)) --outputChatBox (tostring (rotx).." "..tostring (rotz)) return result end Link to comment
DefiniteIntegral Posted August 11, 2008 Share Posted August 11, 2008 That is exactly what I was looking for, thanks. For the convenience of anyone else who searches for it, the vector the car is facing is different from eXo|Mr.Hankey's camera vector by -90 degrees around X axis. local vx = math.cos(math.rad(rx)) * math.sin(math.rad(360-rz)) local vy = math.cos(math.rad(rx)) * math.cos(math.rad(360-rz)) local vz = math.sin(math.rad(rx)) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now