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

[SDASH+] Homing Attack


Recommended Posts

Gave up on making a Chaos Spear for the night, as that is too hard. Figured I could stick Homing Attack in without much trouble. NOPE! XD

Here's what I did; went into the scrPlayerActionJumping, and added this:

case consCharacterShadow:

scrPlayerMotionHomingAttack();

FlagsAllowCommonInput = false;

FlagsAllowDoubleJumpAction = false;

break;

This is scrPlayerMotionHomingAttack:

Action = consActionHomingAttack;

move_towards_point(x,y,speed)

instance_nearest(x,y,objParentEnemy)

And here's what I got: no homing attack, but now if I double jump near an enemy, I get stuck in an infinite roll. I guess that's due to the homing attack script disabling common input, but - that should get turned off by the player action jumping scr, right!?

Can I have a hand please? Cheers! :D

Link to comment
Share on other sites

That code doesn't even make any sense at all. Nearest_instance will grab the ID of nearest instance.

And move_towards_point(x,y,speed) is going to move your towards your current x and y coordinates (AKA your current position) at the current speed which is probably zero because speed is the build in GM speed variable which isn't use in Dash. They are all variables which hold the current values your objPlayer already has.

Its explained in this thread a bit here.

http://sonicunited.org/hsfqmtif/forum/showthread.php?t=7152

Link to comment
Share on other sites

Heh, that's where I started! I am new (bad) at this. I was trying to follow what you said there in that thread, writing that out as I went along. Obviously, that was bad. :P

Hm. Even just copying what Superbliz ended up with doesn't work for me;

Action = consActionHomingAttack;

var _ObjectHandle, _X, _Y;

if instance_number(objParentEnemy)<1 exit;

_ObjectHandle = instance_nearest(x,y,objParentEnemy)

_X = objParentEnemy.x

_Y = objParentEnemy.y

if(abs(x - _ObjectHandle.x) < 100)

{

move_towards_point(_X, _Y, 10); Homing_Lock = 1;

}

if (Ground == true) {

Action = consActionNormal;

FlagsAllowCommonInput = true;

}

This time, I even put the "if back on ground, allow input" thing right there in this script, but I still end up in a permanent roll after double jumping, and no homing attack. :/

Link to comment
Share on other sites

Haha, yeah, forgot to do that. XD

OK, now that's done, here's the progress: double jumping and landing now works, I get control back when I'm on the ground.

But the homing attack itself is borked. Something happens now; Shadow flies towards an enemy, but keeps going, flying to the right of the screen.

Link to comment
Share on other sites

It doesn't look like the the homing attack is getting turned off unless it hits the ground. So its probably homing towards a non existing enemy assuming the enemy is being destroyed when you hit it. So you might want to set the action to jumping after destroying the enemy and set speed to 0 just to make sure its not still moving to any point.

Link to comment
Share on other sites

  • 2 weeks later...

OK, after lots of help from SuperBliz and Chronic, I've nearly got this down.

I still glitch out, and I think I understand why, and I may even have a solution in mind, but it'd be crazy long winded, and maybe there's a simpler solution:

The problem now is this: if the enemy I try to attack is on my LEFT, then homing attack will activate, but instead send me flying off to the RIGHT, to hit the nearest available enemy, even if they're offscreen / behind obstacles when I activated the attack.

I think there may also be an issue with attacking DOWN, as opposed to flying UP into an enemy, but I haven't been able to determine that for sure yet.

So, gents! The solution I had in mind was copy paste the entire code I have, replacing all instances of X with -X so the working code I have for attacking Right also attacks Left. I'm fairly sure that'd work, but it seems sloppy. Is there a tidier way of doing things?

I'm sure now that the problems I have all lie in the enemy detection part of things; if I get that all perfect, then there's no way for a glitchy activation. But failing that, I need a failsafe! Is there anyway to stick in a "if character has been homing attacking for more than a second, then cancel it" type thing, like in Sonic Adventure when you'd glitch, go flying for a while, then drop? Obviously, I want to get to the point that the homing attack never glitches out at all, but still. :P

Is it gonna be possible to implement a cancel to my homing attack, since it isn't a state the character enters into like rolling or anything, it's just a "move character to point" thing?

Link to comment
Share on other sites

I have hit the limits of my coding abilities. Here's what I got:

// ==== FUNCTION ====================================================================

// scrPlayerMotionHomingAttack()

// ==================================================================================

//

Action = consActionHomingAttack;

var _ObjectHandle, _X, _Y;

if(instance_exists(objParentEnemy))

{

_ObjectHandle = instance_nearest(x,y,objParentEnemy)

_X = objParentEnemy.x

_Y = objParentEnemy.y

if(abs(x - _ObjectHandle.x) < 100)

{

move_towards_point(_X, _Y, 10); Homing_Lock = 1;

}

}

else

{

exit;

}

if(Ground == true)

{

Action = consActionNormal;

FlagsAllowCommonInput = true;

}

I figured that changing the ObjectHandle to this:

_ObjectHandle = instance_nearest(x,y,objParentEnemy)

_X = objParentEnemy.x or -x

_Y = objParentEnemy.y or -y

Would mean the homing attack works on the left too, but nope! Just makes Shadow fly off into the sky. Halp? :<

Link to comment
Share on other sites

  • 2 weeks later...

Then that puts me back to where I was, but I have still made no progress. ;D

I can not homing attack anything on the left of the player. I think that's my big problem. Homing attack works fine, as long as your target is on the right, and not too high or too low. So, I need to make it so I can also target enemies on the left. Cause right now, what happens is, the game detects and enemy on the left - but sends me flying off to the right to find the nearest enemy on my right, instead of the one right next to me on the left.

Link to comment
Share on other sites

I think the problem occurred in this code:

"_ObjectHandle = instance_nearest(x,y,objParentEnemy)

_X = objParentEnemy.x

_Y = objParentEnemy.y"

I'm not the best coder, but I think that this might work:

"_ObjectHandle = instance_nearest(x,y,objParentEnemy)

_X = _ObjectHandle.x

_Y = _ObjectHandle.y"

Let me know if this works or not, and if it doesn't, let me know what happened.

  • Like 1
Link to comment
Share on other sites

Since you're having a lot of problems like this, I'll post my code right here. Note this though, the code you're using is outdated. I changed my code after I was done posting in my own thread.


// ------- Define variables ------- //
var _ObjectHandle, _X, _Y;

_ObjectHandle = instance_nearest(x,y,objParentEnemy)
_X = _ObjectHandle.x
_Y = _ObjectHandle.y

// ------- Move towards object ------- //

if (abs(x - _ObjectHandle.x) < 160)
{
Homing_Lock = 1;
Action = consActionHomingAttack;
}
if Homing_Lock=1
{
Speed=0; Gravity=0; sound_play(sndHomingAttack); move_towards_point(_X, _Y, 12.5);
}
// Cancel homing attack if an object is behind a wall
if collision_line(x,y,_X,_Y,objParentTerrain,1,1) && Homing_Lock=1
{
Homing_Lock=0;
speed=0;
}
else
{
Speed=AnimationDirection*6.5;
Gravity-=0.4;

if Ground
{Action=consActionNormal;}
// Reset counter
}
if Ground
{Speed=0; Homing_Lock=0;}[/CODE]

You might encounter a glitch or two because I've removed a lot of variables from this script mainly because you don't have them placed in your engine. I've also changed some parts so it fits with your engine.

  • Like 1
Link to comment
Share on other sites

God dammit Bliz, that works perfectly. :o

I don't understand though, what's different about your targetting from mine? Why would mine not attack on the left? @__@

Thanks a lot, man. <3

EDIT: Bliz, I gotta spread the Rep love around before I rep you again. I won't forget! ;D

Well I think it's because I got all these extra variables and such that's why it works almost perfectly. XP And thanks, rep would be nice. :)

Link to comment
Share on other sites

  • Recently Browsing   0 members

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