Jump to content

[HELP] Rotation


Mature

Recommended Posts

Hello community, Well, I need your help ... I'm trying to create a system in which the player releases an object, and the object is next to the player, regardless of the rotation, I did this check, but it always falls on the first check, regardless of rotation.

local _, _, rotz = getElementRotation(element)
		 outputChatBox(math.floor(rotz), element)
		 if math.floor(rotz) > 0 and math.floor(rotz) < 80  then
	    	 local x,y,z = getElementPosition(element)
	    	 object[element] = createObject(2969, x, y - 1, z - 0.8)
	    	 setObjectScale(object[element],1.4)
	     	 setElementCollisionsEnabled(object[element],false)
			 outputChatBox("1", element)
		 else
    		 if math.floor(rotz) > 165 and 250 < math.floor(rotz) then
    		     local x,y,z = getElementPosition(element)
    	    	 object[element] = createObject(2969, x, y - 1, z - 0.8)
    	    	 setObjectScale(object[element],1.4)
    	     	 setElementCollisionsEnabled(object[element],false)
    			 outputChatBox("2", element)
    		 else
        		 if math.floor(rotz) > 251 and 350 < math.floor(rotz) then
            		 local x,y,z = getElementPosition(element) 
         	    	 object[element] = createObject(2969, x, y - 1, z - 0.8)
        	    	 setObjectScale(object[element],1.4)
        	     	 setElementCollisionsEnabled(object[element],false)
        			 outputChatBox("3", element)
				 end
			 end
		 end

The coordinates are incorrect, I know, but basically I just want help checking the element's rotation.

Link to comment

Hello Hazardinho,

since I have got experience working with rotations I recommend you to use the element's matrix instead, using getElementMatrix. If you look at the wiki page you can see the examples.

Explanation: The element matrix stores the rotation of the ped in a coordinate system axis. If you use setElementRotation then the euler angles are automatically converted into this matrix so this matrix is more powerful and less ambiguous than the angles.

Problem of euler angles: euler angles are periodic in 360° as well as suffering from gimbal lock in MTA:SA (due to poor implementation, not wanting to going into the details).

If you want to use euler angles then you probably need to normalize the angles.

local function normalize_euler(angle)
    while (angle >= 360) do
        angle = angle - 360;
    end
    while (angle < 0) do
        angle = angle + 360;
    end
    return angle;
end

Then if you do the following:

local rotX, rotY, rotZ = getElementRotation(ped);
rotX = normalize_euler(rotX);
rotY = normalize_euler(rotY);
rotZ = normalize_euler(rotZ);

... you are guarranteed to get the angle in the value range including 0 to just below 360.

So if you are clueless on where to start, try using the getPositionFromElementOffset Function from the wiki page using the offset x=0, y=-1, z=-0.8.

- Martin

Edited by The_GTA
  • Thanks 1
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...