Jump to content

Element rotation


IIYAMA

Recommended Posts

  • Moderators
Posted

I am looking for findRotation math, but one that is also returning X and Y rotation.

https://wiki.multitheftauto.com/wiki/FindRotation

function findRotation(x1,y1,x2,y2) 
  
  local t = -math.deg(math.atan2(x2-x1,y2-y1)) 
  if t < 0 then t = t + 360 end; 
  return t; 
  
end 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

use this:

( 360 - math.deg ( math.atan2 ( ( x - px ), ( y - py ) ) ) ) % 360 
  
example: 
x, y, z = getElementPosition( player ) 
px, py, pz = getElementPosition( player2 ) 
local rotation = ( 360 - math.deg ( math.atan2 ( ( x - px ), ( y - py ) ) ) ) % 360 
  

Giving a Fuck? Nope, That isn't in My Skill Set

castie11.png

  • Moderators
Posted
use this:
( 360 - math.deg ( math.atan2 ( ( x - px ), ( y - py ) ) ) ) % 360 
  
example: 
x, y, z = getElementPosition( player ) 
px, py, pz = getElementPosition( player2 ) 
local rotation = ( 360 - math.deg ( math.atan2 ( ( x - px ), ( y - py ) ) ) ) % 360 
  

and how do I get the X and Y rotation?

Because now I also only have the Z rotation.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted
z it's just up or down they not used as rotation thing

nieuwinviz2005-5.jpg

It is.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

1 think we talk about MTA physics not Real life so try my code

to get rotation you can use SetElementRotation( blabla, rotation ) or return rotation

Giving a Fuck? Nope, That isn't in My Skill Set

castie11.png

  • Moderators
Posted
1 think we talk about MTA physics not Real life so try my code

to get rotation you can use SetElementRotation( blabla, rotation ) or return rotation

@ CastielRecords

I didn't make this topic for things I already know, I asked about getting the X and Y rotation based on finding rotation.

Next to that I have lots lua experience with lua, but I don't have with 3D math.

Thanks for trying to help me, but I need somebody with high math skills. :)

Is there anybody who can help me with this?

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
What exactly are you going to use it for? depending on what, you cant get X rotation, only Z and Y.

If you can get the Z rotation, you can also get the X and Y rotation. It's just math with sins, cons and tans.

If I helped you, please click the like button on the right ;) Thanks!

  • Moderators
Posted
What exactly are you going to use it for? depending on what, you cant get X rotation, only Z and Y.

If you can get the Z rotation, you can also get the X and Y rotation. It's just math with sins, cons and tans.

sins, cos and tan isn't JUST this math. I know how they work, but I don't know how to use them with this.

Since my brain can't merge the ordinary math with 3D math......

Pls give me a sample, if it is just sin cos and tan.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
What exactly are you going to use it for? depending on what, you cant get X rotation, only Z and Y.

If you can get the Z rotation, you can also get the X and Y rotation. It's just math with sins, cons and tans.

For example if you are using two points as reference, like in the 'findRotation' function that IIYAMA provided, then you can only get Z and Y rotation. You need at least three points to get roll (X rotation) also, otherwise roll can only be 0.

Posted

Pitch / Yaw ( Y , Z ) roation is prity simple to calculate

It's not coded in LUA , it's C++ , i just C+P it from my old aimbot used in some FPS game's , but the math is the same just need to be recoded to LUA.

  
  
            D3DXVECTOR3 NewVector; 
            NewVector.x = pClientInfo->g_pLocal->Pos.x - g_pESP.pPlayers[AimAt].Aimcords.x; 
            NewVector.y = pClientInfo->g_pLocal->Pos.y - g_pESP.pPlayers[AimAt].Aimcords.y; 
            NewVector.z = pClientInfo->g_pLocal->Pos.z - g_pESP.pPlayers[AimAt].Aimcords.z; 
  
            float CamYaw = (float)atanf(NewVector.x/NewVector.z); 
            if(NewVector.z > 0.0f && NewVector.x < 0.0f && CamYaw < 0.0f) 
                CamYaw += D3DX_PI; 
            else if(NewVector.z > 0.0f && NewVector.x > 0.0f) 
                CamYaw += D3DX_PI; 
  
            DWORD tempKey = 0; 
            switch(AimbotKey) 
            { 
                default: 
                    tempKey = VK_LBUTTON; 
                break; 
            
                case 1: 
                    tempKey = VK_RBUTTON; 
                break; 
                
                case 2: 
                    tempKey = VK_SHIFT; 
                break; 
            } 
            if((GetAsyncKeyState(tempKey) && !Aimbotkeyon) || (Aimbotkeyon)) 
            { 
                pClientInfo->g_pLocal->pitch    = (float)atan2f(NewVector.y,(float)sqrt(pow(NewVector.z,2) + pow(NewVector.x,2))); 
                pClientInfo->g_pLocal->yaw      = CamYaw; 

Ingame Name : |DGT|Puma

DGT Clan Server 24/7 Owner/Scripter

MultiGameMode in progress :

n-560x95_FFFFFF_FFFFFF_0283C4_000000.png

  • Moderators
Posted

what is Pitch and Yaw in lua?

Can you explain a bit more, because I sorry but I have no idea how this is working.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
what is Pitch and Yaw in lua?

Can you explain a bit more, because I sorry but I have no idea how this is working.

In 3D world / plan is Pitch / Yaw / Roll. They are the 3 axis rotation. Pitch = Y rot , Yaw = Z rot , Roll = X rot.

In MTA for a better understanding they call'd them X,Y,Z rot , but in game coding they are call'd Pitch / Yaw / Roll and most of the time they are used on the Camera , Pitch / Yaw is look up-down , left-right , and Roll is used to tilt the camera in MTA one exemple would be the "drunk camera" where it get shake'd.

And even now i can't imagine where you wanna use them.

Ingame Name : |DGT|Puma

DGT Clan Server 24/7 Owner/Scripter

MultiGameMode in progress :

n-560x95_FFFFFF_FFFFFF_0283C4_000000.png

  • 2 weeks later...
Posted
function findPitch(camerax,cameray,cameraz,pointx,pointy,pointz) 
  
local dX=camerax-pointx 
local dY=cameraz-pointz 
local dZ=cameray-pointy 
  
local pitch=math.atan2(dY,math.sqrt(math.pow(dZ,2) + math.pow(dX,2))); 
return pitch 
end 

Converted from bandi's code, already sended to IIYAMA via skype, I just felt of sharing it. And I don't think that Roll is needed. Also it's returned in radians here's the code for converting it to degrees:

local degree = pitchReturn*(180/math.pi) 

pitchReturn = the return of the function "findPitch", it was just a simple google :P

Sometimes I dream about cheese

  • Moderators
Posted

Danny, thank you very much! It works great!

Bandi thanks for explaining about the camera rotation.

It seems it didn't needed the Y rotation after all.

Also thanks to everybody that replied on this topic.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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...