Jump to content

[Help] Problem with moveObject and rotation


MRmihailZH

Recommended Posts

Here is the function that moves the object, I understand that instead of rotation -80, I need to write some formula that will determine how much it needs to lower / rise, but I can’t achieve such a result. Therefore, I ask for your help, thank you in advance.

gateLSPD = false
x, y, z = getElementPosition ( source )
if getDistanceBetweenPoints3D ( x, y, z, 1544.24707, -1631.90906, 13.38281 ) <= 2 then
	if gateLSPD == false then
		local rotX, rotY, rotZ = getElementRotation(shlagLSPD)
		moveObject ( shlagLSPD, 2000, 1544.6999511719, -1630.9000244141, 13.10000038147, 0, -80, 0 )
		gateLSPD = true
		else
		local rotX, rotY, rotZ = getElementRotation(shlagLSPD)
		moveObject ( shlagLSPD, 2000, 1544.6999511719, -1630.9000244141, 13.10000038147, 0, 80, 0 )
		gateLSPD = false
	end
end

 

Link to comment
local gateCommandWaitInMs = 3000 -- 3000 milliseconds. You can increase or decrease this value to meet your requirements
local objectMovingTick = getTickCount() + gateCommandWaitInMs -- we are adding this to tick, so we don't have to wait for 3 seconds in first use
gateLSPD = false
x, y, z = getElementPosition ( source )
if getDistanceBetweenPoints3D ( x, y, z, 1544.24707, -1631.90906, 13.38281 ) <= 2 then
    if (objectMovingTick - getTickCount()) < gateCommandWaitInMs then -- check if 3000 milliseconds have passed
        return 
    end 
    if gateLSPD == false then
        local rotX, rotY, rotZ = getElementRotation(shlagLSPD)
        moveObject ( shlagLSPD, 2000, 1544.6999511719, -1630.9000244141, 13.10000038147, 0, -80, 0 )
        gateLSPD = true
        else
        local rotX, rotY, rotZ = getElementRotation(shlagLSPD)
        moveObject ( shlagLSPD, 2000, 1544.6999511719, -1630.9000244141, 13.10000038147, 0, 80, 0 )
        gateLSPD = false
    end
  
    objectMovingTick = getTickCount()
end

You can use getTickCount to fix the problem.

Edited by Saml1er
Link to comment
On 24/01/2020 at 04:13, Saml1er said:

local gateCommandWaitInMs = 3000 -- 3000 milliseconds. You can increase or decrease this value to meet your requirements
local objectMovingTick = getTickCount() + gateCommandWaitInMs -- we are adding this to tick, so we don't have to wait for 3 seconds in first use
gateLSPD = false
x, y, z = getElementPosition ( source )
if getDistanceBetweenPoints3D ( x, y, z, 1544.24707, -1631.90906, 13.38281 ) <= 2 then
    if (objectMovingTick - getTickCount()) < gateCommandWaitInMs then -- check if 3000 milliseconds have passed
        return 
    end 
    if gateLSPD == false then
        local rotX, rotY, rotZ = getElementRotation(shlagLSPD)
        moveObject ( shlagLSPD, 2000, 1544.6999511719, -1630.9000244141, 13.10000038147, 0, -80, 0 )
        gateLSPD = true
        else
        local rotX, rotY, rotZ = getElementRotation(shlagLSPD)
        moveObject ( shlagLSPD, 2000, 1544.6999511719, -1630.9000244141, 13.10000038147, 0, 80, 0 )
        gateLSPD = false
    end
  
    objectMovingTick = getTickCount()
end

You can use getTickCount to fix the problem.

I tried your code and nothing happens. I tried to fix something and also all to no avail.

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