'Smooth' Enter/Exit object movement
#1

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.
Reply
#2

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).
Reply
#3

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.
Reply
#4

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;
}
Reply
#5

Quote:
Originally Posted by VincentDunn
View Post
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!
Reply
#6

Creative way of using sin values.
Reply
#7

This is why they made a enex marker that kind of disappears in between while its going up and down!

I believe as Y_Less 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.
Reply
#8

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.
Reply
#9

VincentDunn, that is a brilliant thing to do, I really need to learn about floats, i'm missing out on what looks like fun!
Reply
#10

Quote:
Originally Posted by MikeLovesToHelp
View Post
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.
Reply
#11

This is quite interesting to look how people implement advanced maths into SA-MP and whats the outcome!
Reply
#12

Quote:
Originally Posted by RealCop228
View Post
players don't care about those simple things
Its the details that matter.
Reply
#13

Quote:
Originally Posted by Macluawn
Посмотреть сообщение
Its the details that matter.
Well, this will contradict what I previously said, but you're right. The details DO matter, but I honestly don't think people are going to care what this looks like. Most people are content with the small yellow "i" icons, or something.
Reply
#14

The 'i' pickups that servers use are silly. The 'i' is for information. Why would you use that for an interior entrance, apart from the fact that 'i' = interior? The yellow arrow makes more sense. I literally only just realised, as writing this, that the 'i' might mean 'interior'!
Reply
#15

Quote:
Originally Posted by MP2
Посмотреть сообщение
The 'i' pickups that servers use are silly. The 'i' is for information. Why would you use that for an interior entrance, apart from the fact that 'i' = interior? The yellow arrow makes more sense. I literally only just realised, as writing this, that the 'i' might mean 'interior'!
I have to agree, I know what it is scripters suffer from "It's good enough disease" when they should be thinking it's never good enough hence the 'i' will continue to be used improperly.
Reply
#16

I'm the exact opposite. One of the reasons I'm so unmotivated (see THIS topic) is because I always feel like I could do better.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)