MrCode Posted February 16 Share Posted February 16 (edited) Good evening, Community! I need some help calculating an element's rotation based on the following matrix calculation: 'Point_B' is basically the point of which our player or vehicle element is facing towards, we draw a green "+" to show point_B's position on screen. Using processLineOfSight, we are able to show exactly where we're pointing to in the 3D world. The problem is, or what I would really like achieve in this example snippet is, rotating our test object (AK-47) so that it is pointing directly at "Point_B". -- client.lua -- OOP true setElementPosition( localPlayer, -281.52420, 1539.13477, 75.35938 ) -- Test location local theObject = createObject( 355, -281.52420, 1539.13477, 75.35938, 0, 0, 0 ) -- Test object (AK-47) addEventHandler( "onClientRender", root, function ( ) -- CALCULATE "POINT_A" / "POINT_B" ---------------------------------------- local matrix = localPlayer:getMatrix( 0, 0, 0 ) local point_A = matrix:transformPosition( 0, 0, 0 ) local point_B = matrix:transformPosition( 0, 500, 0 ) local hit, x, y, z, element = processLineOfSight( point_A, point_B, true, true, true, false, false, false, false, true, localPlayer ) local hit_start = Vector3( x, y, z ) local point_B = hit and hit_start or point_B local scr = Vector2( getScreenFromWorldPosition( point_B ) ) ---------------------------------------- -- CALCULATE OBJECT ROTATION: -- Point at which I've lost my brain-cells ----------------------------------- local rotX, rotY, rotZ = math.random( 0, 360 ), math.random( 0, 360 ), math.random( 0, 360 ) -- current position of the final brain cell setElementRotation( theObject, rotX, rotY, rotZ ) -- rotate Test object (AK-47) to point to: "Point_B" ---------------------------------------- -- DRAW GREEN TARGET POINT AT: "Point_B" ---------------------------------------- if ( scr.length > 0 ) then dxDrawText( "+", scr - Vector2 ( 0, 0 ), 0, 0, tocolor ( 0, 255, 0, 255 ), 2, "default" ) end end ) Edited February 16 by MrCode Link to comment
Moderators IIYAMA Posted February 16 Moderators Share Posted February 16 3 hours ago, MrCode said: The problem is, or what I would really like achieve in this example snippet is, rotating our test object (AK-47) so that it is pointing directly at "Point_B". See: https://wiki.multitheftauto.com/wiki/FindRotation3D 1 Link to comment
MrCode Posted February 17 Author Share Posted February 17 13 hours ago, IIYAMA said: See: https://wiki.multitheftauto.com/wiki/FindRotation3D Thanks IIYAMA, FindRotation3D worked for the getting rotation. Did not achieve the desired result with a rocket projectile (19) though. Even after rotating it directly at point_B the projectile eventually starts heading out in a different direction, not exactly sure whats up with that. I think an easy way to fix that is using createObject along with moveObject and stuff, but in this case, what should I use to properly send projectiles from point A to point B since createProjectile only has starting position arguments to work with? 1 Link to comment
Moderators IIYAMA Posted February 17 Moderators Share Posted February 17 7 hours ago, MrCode said: Thanks IIYAMA, FindRotation3D worked for the getting rotation. Did not achieve the desired result with a rocket projectile (19) though. Even after rotating it directly at point_B the projectile eventually starts heading out in a different direction, not exactly sure whats up with that. I think an easy way to fix that is using createObject along with moveObject and stuff, but in this case, what should I use to properly send projectiles from point A to point B since createProjectile only has starting position arguments to work with? Are you using this function? https://wiki.multitheftauto.com/wiki/CreateProjectile Attach a dummy vehicle to the object and set the vehicle as the creator of the projectile. Because else your camera is used for the direction. 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