Jump to content

moveObject: Problem with rotation


XetaQuake

Recommended Posts

No, i was on foot, same like the movie i posted, i makes the same way everytime:

Flying with a Jetpack to the object, deaktivate the Jetpack 1 metre above the object and jump on it - now i am on it.

So, there was no vehicle :wink:

I doesn´t understand why this Warning comes, what's wrong with this script?

Link to comment

I made a few mistakes by accident

  
local localPlayer = getLocalPlayer() 
local lastRotation 
local root = getRootElement() 
addEventHandler("onClientRender",root, 
    function() 
        local contactElement = getPlayerContactElement(localPlayer) 
        if contactElement and getElementData(contactElement,"moving") and getElementType(contactElement) == "object" then 
            local a,a,z = getObjectRotation(contactElement) 
            lastRotation = lastRotation or z 
            local difference = z - lastRotation 
            setPlayerRotation ( localPlayer, (getPlayerRotation(localPlayer) + difference)%360 ) 
            lastRotation = z 
        else 
                lastRotation = nil 
        end 
    end 
) 
  

Link to comment
Hey Talidan, thanks for update :D

Its still doesn´t work :( But! - the Warning is away :D

There comes no warnings, no errors and no infos - nothing. (Script is running)

Try this:

  
local localPlayer = getLocalPlayer() 
local lastRotation 
local root = getRootElement() 
addEventHandler("onClientRender",root, 
    function() 
        outputChatBox("A") 
        local contactElement = getPlayerContactElement(localPlayer) 
        if contactElement and getElementData(contactElement,"moving") and getElementType(contactElement) == "object" then 
            outputChatBox("B") 
            local a,a,z = getObjectRotation(contactElement) 
            lastRotation = lastRotation or z 
            local difference = z - lastRotation 
            setPlayerRotation ( localPlayer, (getPlayerRotation(localPlayer) + difference)%360 ) 
            lastRotation = z 
        else 
                outputChatBox("C") 
                lastRotation = nil 
        end 
    end 
) 
  

If you see B appearing in the chatbox, you know it SHOULD work. If you see C, you know there is something wrong with the checking if the player is on an element. If you only see A, well then it's weird! ^^ But it's just to see if you should or shouldn't rotate.

Link to comment

Hey :D

there comes A and B in the same time :?

So, its weird and there is something wrong ^^

Here is the ServerSide script, to set the elemtdata from the object:

  
function tanker_1_go() 
    ... 
    ... 
    ... 
    setTimer ( moveObject, 1000, 1, tanker_1, 25000, tanker_1_waypoint_1_x, tanker_1_waypoint_1_y, transport1_z, 0, 0, tanker_1_waypoint_1_rz ) 
    setTimer ( moveObject, 26000, 1, tanker_1, 6000, tanker_1_waypoint_2_x, tanker_1_waypoint_1_y, transport1_z, 0, 0, tanker_1_waypoint_2_rz ) 
    setTimer ( moveObject, 31000, 1, tanker_1, 30000, tanker_1_waypoint_3_x, tanker_1_waypoint_3_y, transport1_z, 0, 0, tanker_1_waypoint_3_rz ) 
    setElementData(tanker_1,"moving",true) 
end 
addCommandHandler ( "go", tanker_1_go ) 
  

Any ideas :?:

Link to comment
Hey :D

there comes A and B in the same time :?

So, its weird and there is something wrong ^^

Here is the ServerSide script, to set the elemtdata from the object:

  
function tanker_1_go() 
    ... 
    ... 
    ... 
    setTimer ( moveObject, 1000, 1, tanker_1, 25000, tanker_1_waypoint_1_x, tanker_1_waypoint_1_y, transport1_z, 0, 0, tanker_1_waypoint_1_rz ) 
    setTimer ( moveObject, 26000, 1, tanker_1, 6000, tanker_1_waypoint_2_x, tanker_1_waypoint_1_y, transport1_z, 0, 0, tanker_1_waypoint_2_rz ) 
    setTimer ( moveObject, 31000, 1, tanker_1, 30000, tanker_1_waypoint_3_x, tanker_1_waypoint_3_y, transport1_z, 0, 0, tanker_1_waypoint_3_rz ) 
    setElementData(tanker_1,"moving",true) 
end 
addCommandHandler ( "go", tanker_1_go ) 
  

Any ideas :?:

A and B? Then the rotation part should be executed... There's obviously something wrong there... Problem is: What...

I think the problem is in line 14 (setPlayerRotation ( localPlayer, (getPlayerRotation(localPlayer) + difference)%360 )), specifically one of the arguments of setPlayerRotation, since if it would be earlier, you would definetely see calculation errors. (or arithmetic or whatever :P)

By the way... What does %360 do? Isn't that supposed to be + or -?

Link to comment

Nobody knows whats wrong with this script?

  
local localPlayer = getLocalPlayer() 
local lastRotation 
local root = getRootElement() 
addEventHandler("onClientRender",root, 
    function() 
        outputChatBox("A") 
        local contactElement = getPlayerContactElement(localPlayer) 
        if contactElement and getElementData(contactElement,"moving") and getElementType(contactElement) == "object" then 
            outputChatBox("B") 
            local a,a,z = getObjectRotation(contactElement) 
            lastRotation = lastRotation or z 
            local difference = z - lastRotation 
            setPlayerRotation ( localPlayer, (getPlayerRotation(localPlayer) + difference)%360 ) 
            lastRotation = z 
        else 
                outputChatBox("C") 
                lastRotation = nil 
        end 
    end 
) 
  

When i'm not touch the object, i get the output A and C (because of the outputChatBox in the script), and when i on the object, i get A and B - so it SHOULD work, but the player doesn´t rotates.

So my Problem: setPlayerRotation in this script doesn´t work

Any Ideas pleas?

Link to comment

I just tried it, it works fine. However, the object needs to have element data "moving"! And if you move, well, the rotation gets back to where you're moving towards.

Too bad though the player still rotates round his own axis... Would love to see him rotating correctly with my superspeed rotating sub!!!! (only object ID I could find fast enough! ^^)

Link to comment
I just tried it, it works fine. However, the object needs to have element data "moving"! And if you move, well, the rotation gets back to where you're moving towards.

Too bad though the player still rotates round his own axis... Would love to see him rotating correctly with my superspeed rotating sub!!!! (only object ID I could find fast enough! ^^)

First: Thanks that you tried it for me, but i don´t understand it, my object haves elementdata "moving". See here:

function tanker_1_go() 
    ... 
    ... 
    ... 
    setTimer ( moveObject, 1000, 1, tanker_1, 25000, tanker_1_waypoint_1_x, tanker_1_waypoint_1_y, transport1_z, 0, 0, tanker_1_waypoint_1_rz ) 
    setTimer ( moveObject, 26000, 1, tanker_1, 6000, tanker_1_waypoint_2_x, tanker_1_waypoint_1_y, transport1_z, 0, 0, tanker_1_waypoint_2_rz ) 
    setTimer ( moveObject, 31000, 1, tanker_1, 30000, tanker_1_waypoint_3_x, tanker_1_waypoint_3_y, transport1_z, 0, 0, tanker_1_waypoint_3_rz ) 
    setElementData(tanker_1,"moving",true) 
end 
addCommandHandler ( "go", tanker_1_go ) 

hm, now thats realy weird, can do you send me your serverside script, so i can test it with the same script as you.

The player rotates around is own axis? Oh well i thought that already, but its nice that he rotates xD

Hopeful we get a working workaround-script for this problem.

ideas to get the player rotating around the objects axis?

Link to comment
I just tried it, it works fine. However, the object needs to have element data "moving"! And if you move, well, the rotation gets back to where you're moving towards.

Too bad though the player still rotates round his own axis... Would love to see him rotating correctly with my superspeed rotating sub!!!! (only object ID I could find fast enough! ^^)

First: Thanks that you tried it for me, but i don´t understand it, my object haves elementdata "moving". See here:

function tanker_1_go() 
    ... 
    ... 
    ... 
    setTimer ( moveObject, 1000, 1, tanker_1, 25000, tanker_1_waypoint_1_x, tanker_1_waypoint_1_y, transport1_z, 0, 0, tanker_1_waypoint_1_rz ) 
    setTimer ( moveObject, 26000, 1, tanker_1, 6000, tanker_1_waypoint_2_x, tanker_1_waypoint_1_y, transport1_z, 0, 0, tanker_1_waypoint_2_rz ) 
    setTimer ( moveObject, 31000, 1, tanker_1, 30000, tanker_1_waypoint_3_x, tanker_1_waypoint_3_y, transport1_z, 0, 0, tanker_1_waypoint_3_rz ) 
    setElementData(tanker_1,"moving",true) 
end 
addCommandHandler ( "go", tanker_1_go ) 

hm, now thats realy weird, can do you send me your serverside script, so i can test it with the same script as you.

The player rotates around is own axis? Oh well i thought that already, but its nice that he rotates xD

Hopeful we get a working workaround-script for this problem.

ideas to get the player rotating around the objects axis?

Trimentology or something. You need to calculate the distance (2D, meaning X and Y) between the player and the object and change the rotation of it. But I'm getting a start of it at chapter 5 or 6 with maths, while we're yet at 4... -.-

I can send the script I used, you might have something not entirely good I guess?

server:

veh=createObject(9958,-42,-202,5) 
setElementData(veh,"moving",true) 
setTimer(function() local a,a,z=getObjectRotation(veh) setObjectRotation(veh,0,0,z+5) end,100,0) 

client: (exactly the one from a few posts ago)

Try that? (Hint: climb on the sub in the middle, the rest is rotating a bit too fast... xD)

Link to comment

Thanks Gamesnert, i found a mistake in my server side script, now the player rotates around is own axis too :) ( :( ) xD

Soooooo, the last and whole problem is to set the player rotating around the object´s axis!

Trimentology or something. You need to calculate the distance (2D, meaning X and Y) between the player and the object and change the rotation of it. But I'm getting a start of it at chapter 5 or 6 with maths, while we're yet at 4... -.-

Oh well i thought already its anything with mathematic (...i hate it :lol: )

Its realy advanced lua stuff i think, i have not a hunch how it works at this time.

Knows somebody how it works correctly?

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