Cyanide Posted July 23, 2011 Share Posted July 23, 2011 Hey, I'm trying to allow someone to shoot a object and it would rotate to them so the facing side would look away from the wall. Example: A fish shooting script, and the fish point towards you! Everything seems to work but depending on angle the object would lean to much on one side and cause the object to not exactly point at the player. Here's the script below, I commented all my attempts to figure this out. Anyone notice anything wrong? local a = getPedRotation( source ) --x = x + distance * math.sin( -ax ) * 180 / math.pi --y = y + distance * math.sin( -ay ) * 180 / math.pi --z = z + distance * math.sin( -az ) * 180 / math.pi --local rx = x + math.sin (math.rad(-a)) * distance --local ry = y + math.cos (math.rad(-a)) * distance --local r = a + 90.0 createObject ( object, hitX, hitY, hitZ, 0, 0, a + 90 ) Link to comment
SDK Posted July 23, 2011 Share Posted July 23, 2011 I think I understand what you mean, but I don't get what the comments in your code mean. Try a + 180 in your createObject Link to comment
bandi94 Posted July 23, 2011 Share Posted July 23, 2011 local x,y,z = getPedRotation( source ) createObject ( object, hitX, hitY, hitZ, 0, 0, z + 90 ) or use a matrix Link to comment
Cyanide Posted July 23, 2011 Author Share Posted July 23, 2011 local x,y,z = getPedRotation( source ) createObject ( object, hitX, hitY, hitZ, 0, 0, z + 90 ) or use a matrix getPedRotation returns one variable, and that is the rotation of the player. I think I understand what you mean, but I don't get what the comments in your code mean.Try a + 180 in your createObject That definitively wouldn't work. The code in the comments is called Trigonometry. Link to comment
SDK Posted July 23, 2011 Share Posted July 23, 2011 The code in the comments is called Trigonometry. I meant, what do the variables mean ... Anyway, try this local ex, ey, ez = hitX, hitY, hitZ -- 3D point that needs to be rotated local px, py, pz = getElementPosition(source) -- 3D point that needs to be rotated to local rotx = math.atan2 (pz - ez, getDistanceBetweenPoints2D ( px, py, ex, ey ) ) local roty = 0 local rotz = math.pi - math.atan2 ( ( ex - px ), ( ey - py ) ) rotx, roty, rotz = math.deg (rotx), math.deg(roty), math.deg(rotz) return setElementRotation(element, rotx, roty, rotz) createObject ( object, hitX, hitY, hitZ, rotx, roty, rotz ) Link to comment
Cyanide Posted July 23, 2011 Author Share Posted July 23, 2011 It still doesn't work. The object doesn't face me when I'm at certain angles. Link to comment
SDK Posted July 23, 2011 Share Posted July 23, 2011 I accidentally left in the return part, I hope you removed it in your script? I tested it, and it worked, the objects always faced me with the same side. Post the whole thing you made. Link to comment
bandi94 Posted July 23, 2011 Share Posted July 23, 2011 SDK get out if you can-t delet a return part 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