Xierra Posted March 27, 2010 Posted March 27, 2010 Hi guys! I want to ask about this because I don't know how to move by moving and rotating. Something like a car showroom, with camera rotating around the car. I've read the wiki about camera functions. But I don't know how to do a rotating camera on an element (vehicle) like in some servers. I don't know about those 1x like that, My maths aren't as good as that. Can you give me an example of it, so I can make something like that? XX3 is gone. This is my new name. :3
karlis Posted March 27, 2010 Posted March 27, 2010 try this, but its untested: angle=0 function getPointFromDistanceRotation(x, y, dist, angle) --credits to robhol from wiki snippets local a = math.rad(90 - angle) local dx = math.cos(a) * dist; local dy = math.sin(a) * dist; return x+dx, y+dy; end function attachrotatingcamera(bool,element,Zoffset,distance) if bool then element,Zoffset,distance=element,Zoffset,distance --make values global addEventHandler("onClientRender",getRootElement(),createRotRamera) else removeEventHandler("onClientRender",getRootElement(),createRotRamera) end end function createRotRamera() local x,y,z=getElementPosition(element) local camx,camy=getPointFromDistanceRotation(x, y, distance, angle) setCameraMatrix(camx,camy,z+Zoffset,x,y,z) angle=angle+1 --you can change value if angle>359 then angle=0 end end [WIP]GTA IV style hud+custom blips + blip text + circular radar areas
Xierra Posted March 27, 2010 Author Posted March 27, 2010 Okay, but how will this work? What should I do to activate it? XX3 is gone. This is my new name. :3
Gamesnert Posted March 27, 2010 Posted March 27, 2010 It seems like you're supposed to type something like: attachrotatingcamera(true,element,10,20) However, it won't work because this line won't do anything: element,Zoffset,distance=element,Zoffset,distance --(doesn't)make values global This should fix it, although I haven't checked for any other mistake in the code. -- EDIT ME local rotSpeed = 1 -- How much degrees you want the camera to turn per frame -- DON'T EDIT ME ANYMOAR local angle = 0 local elem local zOff local dist function getPointFromDistanceRotation(x, y, dist, angle) --credits to robhol from wiki snippets local a = math.rad(90 - angle) local dx = math.cos(a) * dist; local dy = math.sin(a) * dist; return x+dx, y+dy; end function attachrotatingcamera(bool,element,Zoffset,distance) if bool then elem,zOff,dist=element,Zoffset,distance --make values global addEventHandler("onClientRender",getRootElement(),createRotRamera) else removeEventHandler("onClientRender",getRootElement(),createRotRamera) end end function createRotRamera() local x,y,z=getElementPosition(elem) local camx,camy=getPointFromDistanceRotation(x, y, dist, angle) setCameraMatrix(camx,camy,z+zOff,x,y,z) angle=(angle+rotSpeed)%360 end Projects: Slothbot | Maximap
Xierra Posted March 27, 2010 Author Posted March 27, 2010 (edited) How should I activate the script? *EDIT: I don't mean that, what should I do to rotate around the vehicle by a command for example? karlis hasn't told me yet Edited March 27, 2010 by Guest XX3 is gone. This is my new name. :3
Gamesnert Posted March 27, 2010 Posted March 27, 2010 It seems like you're supposed to type something like: attachrotatingcamera(true,element,10,20) It's the same script, with a couple of fixes, so it works the same way. Projects: Slothbot | Maximap
karlis Posted March 27, 2010 Posted March 27, 2010 too bad signatures are disabled, i would put there disclaimer that my scripts wont work likely just simple command handler added(/rotateme): -- EDIT ME local rotSpeed = 1 -- How much degrees you want the camera to turn per frame -- DON'T EDIT ME ANYMOAR local angle = 0 local elem local zOff local dist local active = false function getPointFromDistanceRotation(x, y, dist, angle) --credits to robhol from wiki snippets local a = math.rad(90 - angle) local dx = math.cos(a) * dist; local dy = math.sin(a) * dist; return x+dx, y+dy; end function attachrotatingcamera(bool,element,Zoffset,distance) if bool then active=true elem,zOff,dist=element,Zoffset,distance --make values global addEventHandler("onClientRender",getRootElement(),createRotRamera) else removeEventHandler("onClientRender",getRootElement(),createRotRamera) setCameraTarget(getLocalPlayer(),getLocalPlayer()) active=false end end function createRotRamera() local x,y,z=getElementPosition(elem) local camx,camy=getPointFromDistanceRotation(x, y, dist, angle) setCameraMatrix(camx,camy,z+zOff,x,y,z) angle=(angle+rotSpeed)%360 end addCommandHandler("rotateme",function() attachrotatingcamera(not active,getLocalPlayer(),5,10) end) [WIP]GTA IV style hud+custom blips + blip text + circular radar areas
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