Accelerating Objects -
Skiaffo - 30.09.2010
Im making a script of a moving ship. To make the movement more realistic im trying to accelerate the ship when it starts moving. Im using this code:
Код:
public MoveShip(Float:speed) {
for (new obj = 0; obj < shiptot; obj ++) {
new Float:x, Float:y, Float:z;
GetObjectPos(obj, x, y, z);
MoveObject(obj, x - 1000, y, z, speed);
}
if (speed >= maxspeed) return 1;
SetTimerEx("MoveShip", 500, 0, "f", speed + 0.2);
return 1;
}
top:
filterscriptinit:
Код:
for (new obj = 0; obj < 100; obj++) {
if (IsValidObject(obj)) shiptot ++;
}
commandtext:
Код:
if (!strcmp(cmdtext, "/move", true)) {
MoveShip(0.0);
return 1;
}
The ship does accelerate, BUT, it does it lagging. The objects of the ship (only 6 atm) rapidly move forward/backward and it's very annoying, then when the ship get to max speed it's all right. But the accelerating process is laggy.
So I tought "maybe a 500 ms timer is too fast", so I put 5 SECONDS timer, the problem doesn't go away. I tryed to change the + 0.2 value to a micro value and to a big value, objects still lag.
So I tough "maybe the for is making this lag", so I removed the for and tryied with only one object. It was still lagging. I tryied to put 5 seconds timer, change the + 0.2 value and using it with only 1 object. Still lagging. The objects rapidly move forward and backward and it's horrible to see.
Objects lag also when the ship decelerates, I won't post the code as it's almost exactly the same as the accelerating one.
This is a filterscript, objects are 6, I am not using a streamer, and maxspeed value is 3.0
How to solve this lagging issue? Thanks.
Re: Accelerating Objects -
Fab10 - 30.09.2010
omg un messaggio dal 2006 xD
AW: Accelerating Objects -
Arrows73 - 30.09.2010
You should consider using vectors for the movements
Re: Accelerating Objects -
Skiaffo - 30.09.2010
I actually have two accounts, the other one is Rlz_Skiaffo where I have 3 messages. I registered it because I didn't remember this account password. Now I didn't remember Rlz_Skiaffo's password and I do remember this one again.
So I have a total of 4 messages (five with this one), but yea, I never asked for help, I always found what I needed. Now I do need help.
Quote:
You should consider using vectors for the movements
|
Can you please be more specific in what you mean and make me short examples? thanks.
Re: Accelerating Objects -
Skiaffo - 01.10.2010
I managed to ALMOST solve the problem. Now the objects seems to go ok, but the player is "slipping" a bit onto the objects when they accelerate and decelerate. I don't think there's much to do about it, I believe it's just a SA-MP problem. I hope im wrong, if you know how to solve this or if you just have another method to accelerate objects please tell me. Here's my actual code:
Код:
#define stopped 0
#define moving 1
#define accelerating 2
#define decelerating 3
new Float:maxspeed = 6.0;
new shiptot = 0;
new shipstatus = stopped;
new Float:speed = 0.0;
Код:
for (new obj = 0; obj < 100; obj++) {
if (IsValidObject(obj)) shiptot ++;
}
Код:
if (!strcmp(cmdtext, "/move", true)) {
if (shipstatus == stopped) {
MoveShip();
shipstatus = accelerating;
}
return 1;
}
if (!strcmp(cmdtext, "/stop", true)) {
if (shipstatus == moving) {
StopShip();
shipstatus = decelerating;
}
return 1;
}
Код:
stock MoveShip() {
for (new obj = 0; obj < shiptot; obj ++) {
new Float:x, Float:y, Float:z;
GetObjectPos(obj, x, y, z);
MoveObject(obj, x - 0.2, y, z, 0.2);
} }
stock StopShip() {
for (new obj = 0; obj < shiptot; obj ++) {
new Float:x, Float:y, Float:z;
GetObjectPos(obj, x, y, z);
MoveObject(obj, x - 0.2, y, z, speed - 0.2);
} }
Код:
public OnObjectMoved(objectid) {
new Float:x, Float:y, Float:z;
GetObjectPos(objectid, x, y, z);
switch (shipstatus) {
case accelerating: {
if (speed >= maxspeed - 0.2) {
speed = maxspeed - 0.001;
MoveObject(objectid, x - 2000, y, z, speed);
if (objectid == shiptot - 1) shipstatus = moving;
return 1;
}
MoveObject(objectid, x - speed, y, z, speed);
if (objectid == shiptot - 1) speed += 0.2;
}
case decelerating: {
MoveObject(objectid, x - speed, y, z, speed);
if (objectid == shiptot - 1) speed -= 0.2;
if (speed <= 0.2) shipstatus = stopped, speed = 0.0;
} }
return 1;
}