Jump to content

Synchronization


lolek123

Recommended Posts

Yo,

I replaced a ped with a much bigger one. A dinosaur :D

Now I want to set him an animation. I'm trying to make him walk. My problem is that he takes big steps, but it seems like he's not moving at all. Is there any way that I could speed him up, so I will synchronize the animation with his actual steps?

Thanks.

Link to comment
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), 
function() 
    txd = engineLoadTXD ( "data/Velociraptor/velociraptor.txd" ) 
    engineImportTXD ( txd, 1 ) 
    dff = engineLoadDFF ( "data/Velociraptor/velociraptor.dff" ) 
    engineReplaceModel ( dff, 1 ) 
    txd2 = engineLoadTXD ( "data/Tyrannosaurus/tyrannosaurus.txd" ) 
    engineImportTXD ( txd2, 2 ) 
    dff2 = engineLoadDFF ( "data/Tyrannosaurus/tyrannosaurus.dff" ) 
    engineReplaceModel ( dff2, 2 ) 
end) 
  
  
addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), 
function() 
    ped1 = createPed ( 1, 2471, -1655, 14, 90 ) 
    ped2 = createPed ( 2, 2471, -1658, 14, 90 ) 
    ped3 = createPed ( 1, 2471, -1661, 14, 90 ) 
    ped4 = createPed ( 1, 2471, -1664, 14, 90 ) 
    ped5 = createPed ( 1, 2471, -1667, 14, 90 ) 
    setPedAnimation( ped1, "FAT", "FatSprint") 
    setPedAnimation( ped2, "FAT", "FatWalk", 0, true, true ) 
end) 
  
addEventHandler( "onClientRender", , smooth ) 
function smooth () 
    root = getRootElement() 
    local x, y, z = getElementPosition( ped2 ) 
    setElementPostion( ped2, x + 10, y, z ) 
end 

Help would be appreciated, thank you. :D

Link to comment

Try this :

ped1 = createPed ( 1, 2471, -1655, 14, 90 ) 
ped2 = createPed ( 2, 2471, -1658, 14, 90 ) 
ped3 = createPed ( 1, 2471, -1661, 14, 90 ) 
ped4 = createPed ( 1, 2471, -1664, 14, 90 ) 
ped5 = createPed ( 1, 2471, -1667, 14, 90 ) 
setPedAnimation( ped1, "FAT", "FatSprint") 
setPedAnimation( ped2, "FAT", "FatWalk", 0, true, true ) 
  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), 
    function() 
        txd = engineLoadTXD ( "data/Velociraptor/velociraptor.txd" ) 
        engineImportTXD ( txd, 1 ) 
        dff = engineLoadDFF ( "data/Velociraptor/velociraptor.dff" ) 
        engineReplaceModel ( dff, 1 ) 
        txd2 = engineLoadTXD ( "data/Tyrannosaurus/tyrannosaurus.txd" ) 
        engineImportTXD ( txd2, 2 ) 
        dff2 = engineLoadDFF ( "data/Tyrannosaurus/tyrannosaurus.dff" ) 
        engineReplaceModel ( dff2, 2 ) 
    end 
) 
  
addEventHandler( "onClientRender", root,  
    function ( ) 
        local x, y, z = getElementPosition ( ped2 ) 
        setElementPosition ( ped2, x + 10, y, z ) 
    end 
) 
  

Link to comment

Using setElementPosition without setting the 5th argument to false will reset the animation. Try something like this for speed-up:

  
local speedmult = 0.1 
  
addEventHandler("onClientPreRender", root, 
    function(timeslice) 
        local x, y, z = getElementPosition(ped2) 
        local vx, vy, vz = getElementVelocity(ped2) 
        local speedmult = speedmult*timeslice 
        vx, vy, vz = vx*speedmult, vy*speedmult, vz*speedmult 
        setElementPosition(ped2, x+vx, y+vy, z+vz, true) 
    end 
) 

As you can see, it gets the velocity of the ped, multiplies it by some value (you can change the speed by editing the speedmult value) and adds it to the position, so it moves in the direction where the animations and control states make it move.

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