Sonic Boss Collision?

Discussion in 'Discussion & Q&A' started by NoneofyourBusiness, Jan 5, 2018.

Thread Status:
Not open for further replies.
  1. NoneofyourBusiness

    NoneofyourBusiness Bag of plums. Member

    Joined:
    Apr 27, 2016
    Messages:
    126
    Location:
    The start
    I'm currently making an engine from scratch in Game Maker Studio for my fangame, and I can't seem to find a way to mimic the way Sonic bounces off of the bosses when they're hit, in the original games. If anyone could give some specific pointers (or GML code, better yet) as to what to do, it would really help!
     
  2. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    The X and Y speeds of Sonic are negated, then divided by 2.
    Code:
    		neg.w	$10(a0)
    		neg.w	$12(a0)
    		asr	$10(a0)
    		asr	$12(a0)
    Some pseudo C code:
    Code:
    	SpeedX = (-SpeedX) / 2
    	SpeedY = (-SpeedY) / 2
    EDIT: I've only got a "rough idea" of GML (just had a quick look now), but your code would probably look something like:
    Code:
    	SpeedX = (-SpeedX) div 2;
    	SpeedY = (-SpeedY) div 2;
     
    Last edited: Jan 5, 2018
    Niko and NoneofyourBusiness like this.
  3. DevEd

    DevEd A lol who occasionally doge nothing Member

    Joined:
    Oct 12, 2012
    Messages:
    268
    Location:
    Somewhere...?
    In GML it would be something like this:
    Code:
    hspeed = (-hspeed) / 2
    vspeed = (-vspeed) / 2
    The semicolons aren't necessary in GML, the script would work fine without them.
     
  4. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
  5. LuigiXHero

    LuigiXHero Well-Known Member Member

    Joined:
    Mar 22, 2014
    Messages:
    280
    It really depends, both ways are correct in a sense. Let me explain. Game Maker has built in variables like hspeed and vspeed that can control objects, basically it moves in the direction you set every frame. However most experienced people forego using the built in stuff and use their own variables for speed and do the calculations themselves (which you should probably do for a sonic engine).

    Also the whole / and div thing is the same it supports both.
     
  6. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    Ah I see, thank you for clear that up.

    I've honestly never used GML before (and probably won't d=), but was just a little curious.
     
Thread Status:
Not open for further replies.