justin123 Posted September 29, 2009 Report Share Posted September 29, 2009 I'm trying to make a homing attack that looks like the one from Sonic Adventure 2, but I need help to figure out how to change the angle based on the distance from Sonic to the target. Lets say the distance from the target is 200 pixels and the target is ahead of Sonic. How do I make the angle go from 180 to 0 as sonic comes in contact with the target? Link to comment Share on other sites More sharing options...
justin123 Posted October 2, 2009 Author Report Share Posted October 2, 2009 no one Link to comment Share on other sites More sharing options...
USC Posted October 5, 2009 Report Share Posted October 5, 2009 I'm assuming you already have a basic homing attack written. So, make code along these lines? If (Homing Attack mode) is true{ If Sonic collides with Enemy{ Sonic.Xvelocity = -Sonic.Xvelocity Homing Attack mode = false } } That'll make Sonic go in the opposite direction. Link to comment Share on other sites More sharing options...
justin123 Posted October 5, 2009 Author Report Share Posted October 5, 2009 I'm assuming you already have a basic homing attack written. So, make code along these lines? If (Homing Attack mode) is true{ If Sonic collides with Enemy{ Sonic.Xvelocity = -Sonic.Xvelocity Homing Attack mode = false } } That'll make Sonic go in the opposite direction. I don't need sonic to go in the opposite direction, i'm just trying to figure out how to make him curve into his target. Link to comment Share on other sites More sharing options...
USC Posted October 5, 2009 Report Share Posted October 5, 2009 Oh, okay. Well, I imagine math and (A^2 + B^2 = C^2) would probably help you there. IE: When Sonic is within 30 pixels or so of the enemy, start using their X distance (absolute value of Sonic's X position - Enemy's X position) and Y distance (same, but for Y), then generate an angle from that. Or, do it the low tech way and constantly add/subtract from Sonic's X & Y position until it equals the enemy's. Link to comment Share on other sites More sharing options...
Aerosol Posted October 23, 2009 Report Share Posted October 23, 2009 You need to run a check every frame (or however GM does it) for sonic's angle of movement compared to the angle away from the target. After the check, have sonic turn a certain amount towards the target. Link to comment Share on other sites More sharing options...
justin123 Posted October 25, 2009 Author Report Share Posted October 25, 2009 do I find the angle distance every frame and then move sonic at a constant rate? Link to comment Share on other sites More sharing options...
Recommended Posts