Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

Null Math loops, slops, curves, that sort of stuff (GM 4,5& 6)


Recommended Posts

By null math, i mean little to no trigonomics, little to no sine calculations, something that a Neandherthal or a Cro-Magnon may understand. :cool:

My 2 cents:

------------------
For 45° slopes
In Slope Create event:
execute a piece of code: raiseamount=(Whatever speed you want)

In Slope right key event:
set SonicObj.x+=raiseamount
set SonicObj.y+=raiseamount
set SonicObj.sprite_index=spr_RunR
-----------------

There you go.

Link to comment
Share on other sites

If you want a truly 360 degree engine than making it "without math" is going to be 100 times more complicated than with math. Trust me.

But simple slopes are extremely easy without math:

//Move Left and Right
if( xspeed > 0)
{
   repeat( xspeed )
   {
      if(collision_right() ) { xspeed=0; break;}
      x += 1;
   }
}
else
{
   repeat( -xspeed )
   {
      if(collision_left() ) { xspeed=0; break;}
      x -= 1;
   }
}

//Slope Movement
repeat(20)
{
   if( !collision_bottom() ) break;
   y += 1;
}
repeat(20)
{
   if( collision_bottom() ) break;
   y -= 1;
}

Collision left right and bottom should correspond to the red, yellow, and blue dots respectively:

sosonic1.png

Link to comment
Share on other sites

That's why I use this little thing as suggested by Smidge some while ago:

//Calculate leftover fraction, so that you only have to deal with an
//intiger movement speed, but don't lose decimal precision smoothness
fractionx += spd;
xmov = fractionx div 1;
fractionx -= xmov;

fractiony += grav;
ymov = fractiony div 1;
fractiony -= ymov;

And act with x/ymov

Link to comment
Share on other sites

By null math, i mean little to no trigonomics, little to no sine calculations, something that a Neandherthal or a Cro-Magnon may understand. :cool:

My 2 cents:

------------------
For 45° slopes
In Slope Create event:
execute a piece of code: raiseamount=(Whatever speed you want)

In Slope right key event:
set SonicObj.x+=raiseamount
set SonicObj.y+=raiseamount
set SonicObj.sprite_index=spr_RunR
-----------------

There you go.

This only works because the slope of a 45 degree incline is 1. Although it is an intelligent way to handle that specific case, it is useless for all other cases. If all you have are 45 degree slopes, then by all means do it this way.

Even if you have a very limited number of slopes, you can pre-calculate the movement ratios. Providing you can tell what the slope is, you can apply the proper ratio.

Ratio table for 15 degree increments is attached.

=Smidge=

Link to comment
Share on other sites

  • 2 weeks later...

AeroGP: I will grant that it's a topic that's not difficult enough to spawn many truly "brilliant" solutions, but in coding, "simple" is in no way an antonym for "intelligent" or "brilliant."

null1024: Buh? You understand Smidge's suggestion more than anything else here? That's kinda hard to believe considering you claimed no knowledge/use of trig, but if you say so...

Link to comment
Share on other sites

That's kinda hard to believe considering you claimed no knowledge/use of trig, but if you say so...

Umm... I never said that, I simply find it hard to understand. I use it, personally. (but on very rare occasions...):D

Link to comment
Share on other sites

Aero... you scare me.

Back on topic:

Collision Event with object slope:
if expression keyboard_check(vk_right) is not true
      set the gravity to 0 in direction 0
      set variable s_jump to 0
      move in direction direction at most speed till a contact with solid objects
      set the vertical speed to 0
else
      set the sprite to slopeRun with scale factor 1
      set the vertical speed to -Y slope movement
      set the horizontal speed to -X slope movement

And you correctly plug in the values.

Link to comment
Share on other sites

Question: how much precision does a Sonic game NEED? Would geometry be too much? Would I miss out on something by using these functions?

In *some* cases, yes. Mainly because theese functions would give precison equal to Sonic Pocket Adventure with it's line based slopes.

Link to comment
Share on other sites

Trig isn't about precision at all. It's about adding a new depth to the movement engine. You could argue that using trig functions gives precision over methods such as "y+=1; x+=1;", but that small bit of code is, itself, trig--albeit in a very rudementary form.

Without trig, you have pretty much just have a 4-directional engine. It won't be less precise (actually much more precise since you don't need to deal with decimals), but it won't be able to loop or quarter-pipe. It'll have a more Old Mario feel (but even they had slope acceleration).

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...