Jump to content

Calculating for moving gate..?


Gamesnert

Recommended Posts

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

I did, but didn't understand a single thing about it... =/

Anyway, thanks. Going to try it as soon as possible. :D

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...