SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Discussion (https://forum.sa-mp.com/forumdisplay.php?f=84)
-   -   'Smooth' Enter/Exit object movement (https://forum.sa-mp.com/showthread.php?t=428581)

MP2 06/04/2013 12:15 PM

'Smooth' Enter/Exit object movement
 
After seeing this topic, and having released my own similar include, I decided I would try something I thought of about 3 years ago, but didn't have the knowledge to do it.

The default enex (enter/exit) markers move up and down. But they don't just move up and down, they slow down at the top and bottom. Obviously it's easy to make them just go up and down with MoveObject and OnObjectMoved or a timer, but it looks crap.

Using sin() and a rapid timer, I managed to re-create the 'smooth' animation. I put two arrows next to each other; one using my smooth sin() script and the other just a simple MoveObject/OnObjectMoved script.

[ame]http://www.youtube.com/watch?v=cb-QEbiBzt8[/ame]

Obviously this is using a rapid timer (as I just said), which is never good. The only way I can think of to lessen the server load is to 'stream' the animated arrows, i.e. only animate them if players are near (within 100 meters). The 'FPS' of that arrow was set to 30. I tried 25 and it looked a bit framey. 30 calls a second, per arrow. There could be hundreds of them on your server.

Here's the code used in that video: http://pastebin.com/A33PRK3e

I'd like to get some feedback on this. Do you think it's worth using resources on something so insignificant? I may create ~300 of these arrows and benchmark the results. One thing worth noting is that for every EXTERIOR exit you create on your server, there will be a matching INTERIOR one. I'd estimate there are about 150 interior enter/exits defaultly available, so you're looking at ~300. A loop of 300, 30 times a second.

MP2 06/04/2013 02:10 PM

Re: 'Smooth' Enter/Exit object movement
 
Yeah I sort of agree. It's a cool thing to have but the negatives severely outweigh the positives. Unless people stand there and stare they probably won't see anyway. I guess I'll just keep them static. Was interesting how I used sin() to do it though, as I'd not though of that before (I'd thought about just incrementing the amount of distance between each frame until the halfway point then reversing it).

MP2 06/04/2013 02:15 PM

Re: 'Smooth' Enter/Exit object movement
 
Nah because it'd look kinda framey and would 'jump' a bit due to the sudden increase/decrease in speed. That's why I used sine; it has a gradual increase in value.

I also made this so I could tell what the different was between each 'step' (tested every 10 degrees):

[12:08:51] Diff at 0 degrees: 0.000000
[12:08:51] Diff at 10 degrees: 0.173648
[12:08:51] Diff at 20 degrees: 0.168371
[12:08:51] Diff at 30 degrees: 0.157979
[12:08:51] Diff at 40 degrees: 0.142787
[12:08:51] Diff at 50 degrees: 0.123256
[12:08:51] Diff at 60 degrees: 0.099980
[12:08:51] Diff at 70 degrees: 0.073667
[12:08:51] Diff at 80 degrees: 0.045115
[12:08:51] Diff at 90 degrees: 0.015192
[12:08:51] Diff at 100 degrees: -0.015192
[12:08:51] Diff at 110 degrees: -0.045115
[12:08:51] Diff at 120 degrees: -0.073667
[12:08:51] Diff at 130 degrees: -0.099980
[12:08:51] Diff at 140 degrees: -0.123256
[12:08:51] Diff at 150 degrees: -0.142787
[12:08:51] Diff at 160 degrees: -0.157979
[12:08:51] Diff at 170 degrees: -0.168371
[12:08:51] Diff at 180 degrees: -0.173648
[12:08:51] Diff at 190 degrees: -0.173648
[12:08:51] Diff at 200 degrees: -0.168371
[12:08:51] Diff at 210 degrees: -0.157979
[12:08:51] Diff at 220 degrees: -0.142787
[12:08:51] Diff at 230 degrees: -0.123256
[12:08:51] Diff at 240 degrees: -0.099980
[12:08:51] Diff at 250 degrees: -0.073667
[12:08:51] Diff at 260 degrees: -0.045115
[12:08:51] Diff at 270 degrees: -0.015192
[12:08:51] Diff at 280 degrees: 0.015192
[12:08:51] Diff at 290 degrees: 0.045115
[12:08:51] Diff at 300 degrees: 0.073667
[12:08:51] Diff at 310 degrees: 0.099980
[12:08:51] Diff at 320 degrees: 0.123256
[12:08:51] Diff at 330 degrees: 0.142787
[12:08:51] Diff at 340 degrees: 0.157979
[12:08:51] Diff at 350 degrees: 0.168371

Shows the difference between the last one and the current one.

ReneG 06/04/2013 08:18 PM

Re: 'Smooth' Enter/Exit object movement
 
You could do cooler things using the trig functions, like explosion circles!
[ame="http://www.youtube.com/watch?v=clYmw4NSexY"]http://www.youtube.com/watch?v=clYmw4NSexY[/ame]

Source
pawn Code:
#include <a_samp>
#include <zcmd>

main() {}

new
    g_timer,
    g_increment = 0,
    g_exploding = 0;

CMD:circle(playerid, params[])
{
    if(g_exploding) return 0;

    new
        Float:x,
        Float:y,
        Float:z;

    GetPlayerPos(playerid, x, y, z);

    g_timer = SetTimerEx("circle_explosion", 250, 1, "ffff", x, y, z, g_increment);
    g_exploding = 1;
    return 1;
}

forward circle_explosion(Float:x, Float:y, Float:z, angle);
public circle_explosion(Float:x, Float:y, Float:z, angle)
{
    if(g_increment <= 360) {
        CreateExplosion(x + (20.0 * floatsin(-g_increment, degrees)), y + (15.0 * floatcos(-g_increment, degrees)), z, 0, 5.0);
        g_increment += 10;
    }

    else {
        g_increment = 0;
        g_exploding = 0;
        KillTimer(g_timer);
    }

    return 1;
}

Isolated 06/04/2013 09:55 PM

Re: 'Smooth' Enter/Exit object movement
 
Quote:

Originally Posted by VincentDunn (Post 2467402)
You could do cooler things using the trig functions, like explosion circles!
http://www.youtube.com/watch?v=clYmw4NSexY

Source
pawn Code:
#include <a_samp>
#include <zcmd>

main() {}

new
    g_timer,
    g_increment = 0,
    g_exploding = 0;

CMD:circle(playerid, params[])
{
    if(g_exploding) return 0;

    new
        Float:x,
        Float:y,
        Float:z;

    GetPlayerPos(playerid, x, y, z);

    g_timer = SetTimerEx("circle_explosion", 250, 1, "ffff", x, y, z, g_increment);
    g_exploding = 1;
    return 1;
}

forward circle_explosion(Float:x, Float:y, Float:z, angle);
public circle_explosion(Float:x, Float:y, Float:z, angle)
{
    if(g_increment <= 360) {
        CreateExplosion(x + (20.0 * floatsin(-g_increment, degrees)), y + (15.0 * floatcos(-g_increment, degrees)), z, 0, 5.0);
        g_increment += 10;
    }

    else {
        g_increment = 0;
        g_exploding = 0;
        KillTimer(g_timer);
    }

    return 1;
}


I've got an idea for this code, how about instead of explosions, it creates fire, all the around, then audio stream comes in "I fell into a burning ring of fire" Just saying!

Macluawn 06/04/2013 10:51 PM

Re: 'Smooth' Enter/Exit object movement
 
Creative way of using sin values.

Kar 07/04/2013 03:10 AM

Re: 'Smooth' Enter/Exit object movement
 
This is why they made a enex marker that kind of disappears in between while its going up and down!

I believe as ****** says, moveobject will work WAY better, instead of 30 per second, how about 3-10. Trust me it won't be choppy if done correctly. SetObjectPos should be more choppy-er but guessing you used so much timers you won't see it. Just try the MoveObject, it'll save you resources.

Scenario 07/04/2013 03:16 AM

Re: 'Smooth' Enter/Exit object movement
 
IMHO, it isn't worth using the resources. From my experience as a server owner, players don't care about those simple things. Just using the include you wrote for the interior enter/exits using the same yellow object would be sufficient enough.

Still, nice job in getting it to work so smoothly.

@VincentDunn: That's fucking awesome. :D

Luis- 07/04/2013 04:04 AM

Re: 'Smooth' Enter/Exit object movement
 
VincentDunn, that is a brilliant thing to do, I really need to learn about floats, i'm missing out on what looks like fun!

MP2 07/04/2013 07:49 AM

Re: 'Smooth' Enter/Exit object movement
 
Quote:

Originally Posted by MikeLovesToHelp (Post 2467555)
I've got an idea for this code, how about instead of explosions, it creates fire, all the around, then audio stream comes in "I fell into a burning ring of fire" Just saying!

Holy shit. As I read this, a woman was singing that song on the TV. Fucking creepy! I've never even heard of that song!

On-topic: I won't bother trying to use MoveObject because I know it'll look bad (there's a few MS delay between thr object stopping and OnObjectMoved being triggered). Plus as said already, nobody would even notice. Not worth the resources.


All times are GMT. The time now is 07:12 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.