Rotating objects
#1

Bit ironic seeing as how I created the first and possibly only tutorial for this, but I need help with rotating objects with MoveObject.

As you should know (if you don't; stop reading you're wasting both mine and your own time), to rotate objects you have to move them, as the rotation parameters in MoveObject are the 'final rotation' - the rotation the object will be in at the end of movement.

The problem I have is I am trying to make a RotateObject(objectid, rx, ry, rz, speed) function by moving the object down by 0.001 with SetObjectPos then moving it to the original Z position through MoveObject, thus not affecting the position of the object.

It works fine but the problem is, if the rotation if half way through and I rotate it back, it takes twice as long.

This is the current code I have:

pawn Код:
stock RotateObject(objectid, Float:rx, Float:ry, Float:rz, Float:speed)
{
    if(!IsValidObject(objectid)) return 0;

    speed = 0.0001 * speed;
   
    new Float:x, Float:y, Float:z;
    GetObjectPos(objectid, x, y, z);
    SetObjectPos(objectid, x, y, z-0.0001);
    MoveObject(objectid, x, y, z, speed, rx, ry, rz);
    return 1;
}
Is it just not syncing fast enough or what? I tried StopObject() before also.

I'm thinking an alternative could be to swap it around. Move it up by 0.0001 with MoveObject then move down by 0.0001 in OnObjectMoved, but that'd require variables and this method has no variables which is obviously better. Shame it doesn't work though.

Any ideas?

EDIT: Thinking about it now, using OnObjectMoved may be a better idea after all, as this method may lead to the object rising up (though not by much) for example say you have a barrier at the SFPD and you have a lot of cops coming in and out of it, and as it's closing someone re-opens it, it will be lowered by 0.0001 and then moved up to +0.0001, causing it to be higher than it was originally. So I may do that instead.
Reply
#2

---- 4char
Reply
#3

Read my post.
Reply
#4

pawn Код:
stock SetObjectRotEx(iObjID, Float: fRX, Float: fRY, Float: fRZ, Float: fSpeed)
{
    new Float: fX, Float: fY, Float: fZ ;
    if(GetObjectPos(iObjID, fX, fY, fZ))
    {
        return MoveObject(iObjID, fX, fY, fZ + 0.001, fSpeed, fRX, fRY, fRZ);
    }
    return 0;
}
That should work
Reply
#5

Wait, what? Did you not read my post also? If I move it up by 0.001 every time it gets rotated, after 100 rotates it will have moved up by 0.1. It needs to move up and down.
Reply
#6

Quote:
Originally Posted by MP2
Посмотреть сообщение
It works fine but the problem is, if the rotation if half way through and I rotate it back, it takes twice as long.
Did you stop object before start rotate it back ?

Quote:

Use this function to stop a moving object, for example after using MoveObject.
Код:
StopObject(obj);
EDIT:
Did you try to print out Floatpeed may be is something wrong with value of speed?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)