Sinusoid Motion

Sinusoid Motion via Script

O Ilusionista

Captain 100K
This is something I am trying to do since I ever started in OpenBOR and I am very proud of it: to use SIN and COS math functions to make Sinusoid motion with pure script. I am pretty confortable to work with this in Mugen, but in OpenBOR is a different thing.
 
Last edited by a moderator:
Great O'!!
However if you want that your time start always from 0 you can change your base code:

Code:
ondrawscript @script
void main() {
        void self = getlocalvar("self");
        void time = openborvariant("elapsed_time");
        void elapsed_time = openborvariant("elapsed_time");
	float x = getentityproperty(self, "x");
	float z = getentityproperty(self, "z");
	float y = getentityproperty(self, "y");
	float base = getentityproperty(self, "base");

        // store coords
	if ( getlocalvar("x") == NULL() ) setlocalvar("x", x);
	if ( getlocalvar("y") == NULL() ) setlocalvar("y", y);

        // time start time to 0
        if ( getlocalvar("start_time") == NULL() ) setlocalvar("start_time",time);
        time -= getlocalvar("start_time");

        x = getlocalvar("x") - sin(time/1.45)*2;
        y = getlocalvar("y") - cos(time/1.45)/3;
        changeentityproperty(self, "tosstime", elapsed_time+1) ;
        changeentityproperty(self, "position", x, NULL(), y) ;
 }
@end_script

Than to make the script more flowing I applied the script to ondrawscript event ^__^
Ps. I applied your script to x and y coords (instead of x and z)!
Ps2. To fix the position coords you 've to store initial coords
 
Thanks man, is what I was trying to do last night, but I was asleep, lol.

I haven't used as ondraw because I don't want it to be applied in all animations.
Plus, dunno why, but subject_to_minz or maxz isn't working.

btw, why tosstime? Antigravity won't be sufficient?
 
O Ilusionista said:
Thanks man, is what I was trying to do last night, but I was asleep, lol.

I haven't used as ondraw because I don't want it to be applied in all animations.
Plus, dunno why, but subject_to_minz or maxz isn't working.

btw, why tosstime? Antigravity won't be sufficient?

Yes, Antigravity is sufficient, but if you want an entity subject to gravity (to avoid falling bugs) but with a sinusoid motion you can set tosstime.
Ps. I not tested my code yet.
Ps2. remember to store initial coords too.
 
BeasTie said:
What kind of things would you use this for?

You mean the Sinusoid or the Bézier Curves?

For the first one, I am using it in Storm's hurricane, take a look:
Storm & Psylocke helpers preview
Also, the same happens on the video Rafhot had linked use the same feature.

About the Bézier Curves, there are tons of game which use this feature. Contra, Castlevania and many other.

Alien Soldier from Genesis uses it, at 0:51
http://youtu.be/6M_c_FsbdsM?t=51s
 
O Ilusionista said:
Thank you boss.
I will try to archive my next goal - Bézier curves in OpenBOR.

Wish me luck :)

Great O'!!

Bezier Curve (cubic):
B(t) = P0*(1-t)^3 + 3*P1*t*(1-t)^2 + 3*P2*t^2*(1-t) + P3*t^3
with t in [0,1]

For the algorithm use this general forumla:
index.php

(1st sum)

example:
index.php

using Bernstein algorithm.

For coefficients use the easy Tartaglia/Pascal triangle:
tartagliatriangle.jpg

ex.:
1 3 3 1 -> 1+3 = 4, 3+3 = 6, 3+1 = 4
1 4 6 4 1 -> 1+4 = 5, 4+6 = 10, 6+4 = 10, 4+1 = 5
1 5 10 10 5 1 -> etc...


where P is a point coord like P.x & P.y
P0 is the start point
P3 is the end point
and P1, P2 are check points

so only for x coord calculate (cubic B): x = x0*(1-t)^3 + 3*x1*t*(1-t)^2 + 3*x2*t^2*(1-t) + x3*t^3
where x0 is start, x3 is the end, and x1 & x2 are intermediate x coords.

[attachment deleted by admin]
 
O Ilusionista said:
Question: if we can use SIN and COS in OpenBOR, probabily we can use PI and ATAN too, right?
I know there is a library in C for that, but dunno if it works in OpenBOR too.

Nope, sorry...
However I hope these my funcs can help you:

Code:
float tan(float teta) {
    return (sin(teta)/cos(teta));
}

float arcsin(float alpha) {
    float degrees = 0;
    float pi = 3.141592653589793;

    if ( alpha < -1 || alpha > 1 ) return NULL();

    degrees = 1/sin(alpha);
    degrees *= 180/pi; // radiants to degrees

    return degrees;
}

float arccos(float alpha) {
    float degrees = 0;
    float pi = 3.141592653589793;

    if ( alpha < -1 || alpha > 1 ) return NULL();

    degrees = 1/cos(alpha);
    degrees *= 180/pi; // radiants to degrees

    return degrees;
}
 
Woah! This thread is really interesting.

Could you put an example of how to use those functions?
 
@ Goliath
Could you put an example of how to use those functions?
You can use arcsin and arccos on a setdrawmethod to rotate the entity gradually. IOW, to make an entity to spin forever.

There are tons of usages for sin/cos:

- Make boomerang type projectiles
- Simulate fricction/easing on the ground (this is ubber cool!)
- Make wavy projectiles that moves up and down (in x, y or z axis)
- Make projectiles that "bounces" on the ground many times (althought I would use a different approch)
- Remember Megaman's Leaf Shield/Skull Barrier/all those spinning circles or Castlevania Stone Circle? That ones too.

This is what I had used to code (in Mugen) the first boss (incomplete) of this video. Notice that the spheres are thrown and they return to the original position, even when the original position have changed
My chars - Super Nostalgia Wars

On the original game, the movement was even crazier (at 2:32)
Alien Soldier stages 1 to 7

- Make things vanish and reappear with alpha in loops
- Scale things in loops.

The usage is endless.
 
Only on request I can post the following scripts (already completed for my TMNT Shell Shocked):
- Boomerang weapon with de/acceleration (horizontal and vertical)
- Friction/easing simulation on the ground
- Bouncing effect (horizontal and vertical)
- Roto-traps like TMNT 1 NES (Water Level) -> See 1:02
  https://www.youtube.com/watch?v=9SJVsdCaLeA
- Parabolic move and range calculation
- Change animation based on parabolic move (like an arrow)
- Vertical flying movement -> See 3:50
  https://www.youtube.com/watch?v=Wm0LJoh_RIE

However I used sin/cos only for parabolic move, roto-traps and vertical boomerang for now ^__^
 
Back
Top Bottom