SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 06/04/2013, 12:15 PM   #1
MP2
Godfather
 
MP2's Avatar
 
Join Date: Jan 2011
Location: England
Posts: 6,230
Reputation: 992
Default '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.
__________________
Click banner above for more info. View trailers here.
Enter referral code SAMPFORUM after registering for a $5000 starting bonus!
MP2 is offline   Reply With Quote
Old 06/04/2013, 02:10 PM   #2
MP2
Godfather
 
MP2's Avatar
 
Join Date: Jan 2011
Location: England
Posts: 6,230
Reputation: 992
Default 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).
__________________
Click banner above for more info. View trailers here.
Enter referral code SAMPFORUM after registering for a $5000 starting bonus!
MP2 is offline   Reply With Quote
Old 06/04/2013, 02:15 PM   #3
MP2
Godfather
 
MP2's Avatar
 
Join Date: Jan 2011
Location: England
Posts: 6,230
Reputation: 992
Default 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.
__________________
Click banner above for more info. View trailers here.
Enter referral code SAMPFORUM after registering for a $5000 starting bonus!

Last edited by MP2; 06/04/2013 at 04:05 PM.
MP2 is offline   Reply With Quote
Old 06/04/2013, 08:18 PM   #4
ReneG
High-roller
 
Join Date: Oct 2011
Location: Sublime Text 2
Posts: 1,907
Reputation: 337
Default 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;
}
ReneG is offline   Reply With Quote
Old 06/04/2013, 09:55 PM   #5
Isolated
Gangsta
 
Isolated's Avatar
 
Join Date: Mar 2013
Location: United Kingdom
Posts: 802
Reputation: 155
Default Re: 'Smooth' Enter/Exit object movement

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!
Isolated is offline   Reply With Quote
Old 06/04/2013, 10:51 PM   #6
Macluawn
Gangsta
 
Macluawn's Avatar
 
Join Date: Aug 2010
Location: Latvia
Posts: 613
Reputation: 78
Default Re: 'Smooth' Enter/Exit object movement

Creative way of using sin values.
Macluawn is offline   Reply With Quote
Old 07/04/2013, 03:10 AM   #7
Kar
Banned
 
Join Date: May 2010
Location: Black Asylum
Posts: 2,940
Reputation: 538
Default 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.
Kar is offline   Reply With Quote
Old 07/04/2013, 03:16 AM   #8
Scenario
Godfather
 
Scenario's Avatar
 
Join Date: Feb 2010
Location: Heaven
Posts: 7,809
Reputation: 701
Default 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.
__________________



Scenario is offline   Reply With Quote
Old 07/04/2013, 04:04 AM   #9
Luis-
High-roller
 
Luis-'s Avatar
 
Join Date: Jan 2010
Location: England
Posts: 3,917
Reputation: 391
Default 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!
__________________
Luis- is offline   Reply With Quote
Old 07/04/2013, 07:49 AM   #10
MP2
Godfather
 
MP2's Avatar
 
Join Date: Jan 2011
Location: England
Posts: 6,230
Reputation: 992
Default Re: 'Smooth' Enter/Exit object movement

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.
__________________
Click banner above for more info. View trailers here.
Enter referral code SAMPFORUM after registering for a $5000 starting bonus!
MP2 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] zDevon Tutorials 19 18/07/2015 10:32 PM
[Include] [INC] Smooth Object Rotating [nl]daplayer Includes 18 28/10/2013 01:46 AM
I object to the other party is not smooth properly Omirrow Scripting Help 0 15/02/2013 08:32 PM
Object ID enter/exit Qur Scripting Help 7 10/11/2011 01:44 PM
how to create an /exit and /enter command to enter an costum interior? sandisk125 Help Archive 5 18/08/2009 02:07 PM


All times are GMT. The time now is 04:31 AM.


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