Jump to content

Element rotation


IIYAMA

Recommended Posts

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

Link to comment
  • Moderators
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?

Link to comment
  • Moderators
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.

Link to comment
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.

Link to comment

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; 

Link to comment
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.

Link to comment
  • 2 weeks later...
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

Link to comment
  • Moderators

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.

Link to comment

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