Jump to content

moveObject: Problem with rotation


XetaQuake

Recommended Posts

Can anyone help me pleas?

I have a Idea, possible it works when i get the rotation of the object and add it to the player. But the Problem is that such a function can´t launches so many times...and stuff like "OnClientRender" are also not a perfect solution - also its Client-Side.

Any ideas?

Link to comment

Maybe your idea is good. And why couldn't you use it on every frame? That shouldn't be very difficult. You only need to get contact element with getPlayerContactElement, then check its rotation changes and add the value to the player's rotation.

Link to comment
Maybe your idea is good. And why couldn't you use it on every frame? That shouldn't be very difficult. You only need to get contact element with getPlayerContactElement, then check its rotation changes and add the value to the player's rotation.

Why couldn't you use it on every frame... Ehm... onClientRender IS every frame? :P

Link to comment
Yea but onClientRender is Client Side. And the Object that moves are Server-Side.

I am not able to make a bright between it :/ I understand Client side, i understand Server side - but not to use it together

I think that's one of the most difficult parts of scripting for MTA to be honest. It's not always that easy as triggerServerEvent or triggerClientEvent and you done... =/

Anyway, you got a point there... setTimer(lolz,50,1,...) then?

Link to comment
Yea but onClientRender is Client Side. And the Object that moves are Server-Side.

I am not able to make a bright between it :/ I understand Client side, i understand Server side - but not to use it together

There would be a problem if you needed to rotate a client-side object with server-side script. What does stop you from getting contact element and rotation?

Link to comment
setTimer(lolz,50,1,...) then?

Are you crazy :D That should not so healthy for a Server :lol:

moreover, 50 miliseconds are to slow to let it works smoothly

Also i am not sure that´s the idea to rotate the player works, BECAUSE:

The object is long, so, when it rotates and you stand on the end, you fall down.

Now, when you just rotate the player, the player rotates around his own axis - and he still fall down.

Link to comment
setTimer(lolz,50,1,...) then?

Are you crazy :D That should not so healthy for a Server :lol:

Lol did you look at the function name? It's called "lolz", you think I did that for nothing? :D

Anyway, why is 50ms too laggy? I mean, sure framerate is shorter. But still 50ms gets executed bout 20 times... For as far as I know, the average person averagly sees 25 FPS. What would be wrong with the time? 5 frames delay in a full sec... :P

By the way, can't you just use no rotation at all? They can use their gun and RP the rotation? ^^

Link to comment
Also i am not sure that´s the idea to rotate the player works, BECAUSE:

The object is long, so, when it rotates and you stand on the end, you fall down.

Now, when you just rotate the player, the player rotates around his own axis - and he still fall down.

Maybe it's better to get offset of player position from object, when object rotates, get the position with that offset and move player to that position.

Link to comment

Just because the object is serverside does not mean you can't do it clientside!!!

You dont need to overcomplicate things with triggerClientEvent or triggerServerEvent.

This is one way you could easily do it:

  
local localPlayer = getLocalPlayer() 
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) 
            setPlayerRotation ( localPlayer, z ) 
        end 
    end 
) 
  

Then serverside:

  
moveObject (whatever,124,12561,163) 
setElementData(whatever,"moving",true) 
  
--When its finished moving 
setElementData(whatever,"moving",false) 
  

Link to comment

I don't think he wants to exactly rotate with the object... If you're getting on top of it at a direction of 90, and the object rotates, you'll stand in exactly the objects rotation... So in fact, it's true that you can do some things client-side, but you still have some problems... And is that synched?

Link to comment
I don't think he wants to exactly rotate with the object... If you're getting on top of it at a direction of 90, and the object rotates, you'll stand in exactly the objects rotation... So in fact, it's true that you can do some things client-side, but you still have some problems... And is that synched?

Just offset the rotation then, or measure the changed rotation each frame and increment by that.

Link to comment

Hey guys :D

First: thanks for all the replays :shock::)

I tested Talidans great script. Here is a movie, pleas look it, so you understand the last problems.

There are, as Gamesnert and Talidan already discuss it, two Problems.

First: you are not able to run freely, because the rotation gets updated every time.

Second: You rotate around your own axis, so you still fall down (see movie)

I think its needed to set the rotation relatively to the object or so, but i don´t know how its possible to get a axis from an rotating object :?:lol:

Any ideas?

PS: I think Talidan has mentioned this problem in his last post, right?

Link to comment

Trigonometry is not the problem. You can solve this problem with maths (calculating the right position and rotation that is). What you can't solve is the fact that you can't move when you update the players' position every frame. I am not trying to demoralize anyone, but I personally think it can't be done with the current GTA or MTA physics. But feel free to prove me wrong.

Link to comment

Unfortunately, there is no such even as "onElementMove" or "onElementRotate" or something... Neither are client-side versions, so we need to build it round the object stuff.

Maybe you can do a table which you index with elements. So if you're standing on a box, it should have the index of the element you're standing on. Then you should save the object's current rotation with "getObjectRotation" and see if it has changed. If so, how much it has changed. Then, you should use "setPlayerRotation" and "getPlayerRotation" to set&get the rotation. (ofcourse setting the player rotation as the current rotation+object rotation)

Hope that helps? ;)

@Ace_Gambit: Then you can try to do it every 2 frames? It might indeed be a bit dangerous for moving... But well, we can better test&try than just sit, wait and keep thinking if that's true... =/

Link to comment

Try this:

  
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) + z ) 
        else 
                lastRotation = nil 
        end 
    end 
) 
  

You might have to add checks for aiming players

Link to comment

Hey all. Thanks for all the Replays =)

Talidan, i tries your new and nice code, but i get a WARNING and so it doesn´t works.

Here a the Debugscript 3 warning message:

WARNING: transport_c.lua: Bad 'rotation' pointer @ 'setPlayerRotation'(2) - Line 12

This is Line 12:

setPlayerRotation ( localPlayer, getPlayerRotation(localPlayer) + z ) 

Now the strange thing: why it doesn´t work?

"localPlayer" should be correctly:

local localPlayer = getLocalPlayer() 

Any ideas?

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