Shidony Posted March 6, 2013 Share Posted March 6, 2013 Hi everyone, i'm trying to make a system just for fun but there's a thing i can't do. I downloaded this script (https://community.multitheftauto.com/index.php?p= ... ils&id=469) but i want to edit it to make the object go in the air with the player camera angle. I explain better, with this script, the object is throwed at the same z pos of the player, i want to throw the object in the air if i look in the sky or throw it on the ground if i look the ground but i don't know how to get the camera angle. Can you help me ? Thanks in advance, Cordialy. Link to comment
50p Posted March 6, 2013 Share Posted March 6, 2013 I'm trying to think what you actually want to do.. I can't really think of the "camera angle" you're thinking about. Link to comment
Shidony Posted March 6, 2013 Author Share Posted March 6, 2013 See this image: http://upload.wikimedia.org/wikipedia/c ... stique.jpg I'm trying to search the ϴ angle. Imagine that the canon is a player. Link to comment
guix Posted March 6, 2013 Share Posted March 6, 2013 Hello, Using getCameraMatrix, you have the direction vector of where the player is looking Link to comment
Shidony Posted March 6, 2013 Author Share Posted March 6, 2013 Yes i know this function but i don't know how to calcul the angle with the coords i get. Link to comment
guix Posted March 6, 2013 Share Posted March 6, 2013 (edited) You can do it with function atan2 Ok it's not easy when you don't know where to start, so here is a little example: function getAnglesBetweenPoints3D( x1, y1, z1, x2, y2, z2 ) x1 = x2 - x1 y1 = y2 - y1 x2 = math.atan2( x1, y1 ) * 57.29578 y2 = math.atan2( z2 - z1, math.sqrt( (x1 * x1) + (y1 * y1) ) ) * 57.29578 return x2, y2 end function displayAngles() local x1, y1, z1, x2, y2, z2 = getCameraMatrix( localPlayer ) local a1, a2 = getAnglesBetweenPoints3D( x1, y1, z1, x2, y2, z2 ) outputChatBox( string.format( "a1 = %.2f a2 = %.2f", a1, a2 ) ) end addEventHandler( "onClientRender", root, displayAngles ) The angle you asked is a2, but you will need a1 as well isn't it? Edited March 6, 2013 by Guest Link to comment
Shidony Posted March 6, 2013 Author Share Posted March 6, 2013 I didn't saw you edited your post, i don't understand why you're using cx1, cy1 etc ... but i found this function: local function getCameraRotation() local px, py, pz, lx, ly, lz = getCameraMatrix() local rotz = 6.2831853071796 - math.atan2 ( ( lx - px ), ( ly - py ) ) % 6.2831853071796 local rotx = math.atan2 ( lz - pz, getDistanceBetweenPoints2D ( lx, ly, px, py ) ) --Convert to degrees rotx = math.deg(rotx) rotz = -math.deg(rotz) return rotx, 180, rotz end I teste it and it works but know, i need to find the velocity, i allready have the velocity for x and y but fox z a cannot find the calculation to make the object go into the air and then, fall to the ground with a gravity. EDIT: found the solution, i do not have to convert the rotx into degrees. thanks for your help . Link to comment
Shidony Posted March 7, 2013 Author Share Posted March 7, 2013 This is what i was thinking ^^. So now, i have done my system correctly but the objects hich doesn't have a mass, doesn't fall to the ground, i'm trying to make a virtual gravity but how ? Link to comment
50p Posted March 7, 2013 Share Posted March 7, 2013 If you got them shoot at the right angle then simply decrease its Z coord to make a fake gravity look. Link to comment
Shidony Posted March 7, 2013 Author Share Posted March 7, 2013 That's what i wanted to do but what solution do you think is better, make another setElementVelocity or a moveObject ? Link to comment
50p Posted March 7, 2013 Share Posted March 7, 2013 You could use setElementVelocity with lower velocity. Doesn't setElementVelocity simulate physics/gravity? Link to comment
Shidony Posted March 7, 2013 Author Share Posted March 7, 2013 I allready use setElementVelocity to throw my object in the air, but not all objects get back to the ground, i tested it with a basket ball, it fall to the ground, but a computer doesn't. Link to comment
50p Posted March 7, 2013 Share Posted March 7, 2013 There was a function https://wiki.multitheftauto.com/wiki/IsObjectStatic but I'm not sure if it still works with newer MTA. Anyway, if object has some gravity properties then it will react to gravity otherwise you will have to script it yourself. To make smooth movement you'll need to use onClientRender and roughly calculate current frame position based on velocity and use setElementPosition instead of setElementVelocity. Link to comment
Shidony Posted March 7, 2013 Author Share Posted March 7, 2013 Thanks, i'll try to do that 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