Jump to content


Photo

How to do a Ricochet?


  • Please log in to reply
16 replies to this topic

#1 Bladestorm Games

Bladestorm Games

    GMC Member

  • GMC Member
  • 319 posts
  • Version:GM8

Posted 17 February 2012 - 04:25 AM

Alright so I'm trying to make objAbilitiesRicochet move towards the closest enemy, then hit the enemy doing damage, then bounce of the enemy to the 2nd closest enemy, and so on. Also there will be a skill tree, so you can increase the number of bounces by 1 when global.ability_tree_ricochet += 1 (The skill starts at 3 bounces)

Could someone help me out with that? Thanks!
  • 0

#2 rude guss

rude guss

    GMC Member

  • GMC Member
  • 236 posts

Posted 17 February 2012 - 04:39 AM

Alright so I'm trying to make objAbilitiesRicochet move towards the closest enemy, then hit the enemy doing damage, then bounce of the enemy to the 2nd closest enemy, and so on. Also there will be a skill tree, so you can increase the number of bounces by 1 when global.ability_tree_ricochet += 1 (The skill starts at 3 bounces)

Could someone help me out with that? Thanks!


I did something like this in one of my spells in my rts engine. You can find this in my sig (awesome 2d rts engine, its open source). It worked something like this (mostly psuedo code!!!):

create event
bounces = global.ability_tree_ricochet;
target = instance_id//you set this up yourself;
targetable_obj = object//set this up yourself

step event
if (bounce==0)
{
    instance_destroy();
}

if (instance_exists(target))
{
    if (distance_to_object(target)>=0)
    {
        //move to target - do this yourself
    }
    else
    {
        bounces -= 1;
        //deal damage - do this your self
        instance_deactivate_object(target);
        tmp_nrst = instance_nearest(targetable_obj);
        instance_activate_object(target);
        target = tmp nrst;
    }
}
else
{
    instance_destroy();
}

This is should be compatible with the unregistered version of gamemaker.

Also note that my solution is quite weird, and may not be the best possible solution.

Edited by rude guss, 17 February 2012 - 04:45 AM.

  • 0

#3 Bladestorm Games

Bladestorm Games

    GMC Member

  • GMC Member
  • 319 posts
  • Version:GM8

Posted 17 February 2012 - 04:43 AM

Thanks for the quickest reply ever! Ill be checing this out in about 30minutes, busy atm, again thank you

Alright so what do i put in place of tar?
bounces = global.ability_tree_ricochet
target = tar
targetable_obj = objBasicParentEnemy

Edited by Faultekaiser, 17 February 2012 - 09:10 AM.

  • 0

#4 Bladestorm Games

Bladestorm Games

    GMC Member

  • GMC Member
  • 319 posts
  • Version:GM8

Posted 18 February 2012 - 02:47 AM

Does anyone else have a good ricochet system?
  • 0

#5 4 KINGS

4 KINGS

    BioThirst Studio

  • New Member
  • 549 posts
  • Version:GM8

Posted 18 February 2012 - 02:53 AM

Does anyone else have a good ricochet system?

You must wait 48 hours before double posting.
Also, what's wrong with the one that rude guess has supplied you with?
  • 0

#6 rude guss

rude guss

    GMC Member

  • GMC Member
  • 236 posts

Posted 18 February 2012 - 03:42 AM

Thanks for the quickest reply ever! Ill be checing this out in about 30minutes, busy atm, again thank you

Alright so what do i put in place of tar?
bounces = global.ability_tree_ricochet
target = tar
targetable_obj = objBasicParentEnemy


replace tar with 'noone'

then, in the event that you use your skill do something like this:
ric = instance_create(x,y,objAbilityRicochet);
ric.target = target//store the targeted enemy in this variable

  • 1

#7 Bladestorm Games

Bladestorm Games

    GMC Member

  • GMC Member
  • 319 posts
  • Version:GM8

Posted 18 February 2012 - 05:20 AM


Thanks for the quickest reply ever! Ill be checing this out in about 30minutes, busy atm, again thank you

Alright so what do i put in place of tar?
bounces = global.ability_tree_ricochet
target = tar
targetable_obj = objBasicParentEnemy


replace tar with 'noone'

then, in the event that you use your skill do something like this:
ric = instance_create(x,y,objAbilityRicochet);
ric.target = target//store the targeted enemy in this variable


Alright, I added the new code, but now when the ricochet object (objAbilitiesRicochet) is created, it doesnt appear:

So when the character presses E an object called "objAbilitiesRicochetCreating" is created, after about 2 seconds (animation end event) objAbilitiesRicochet is created, but it doesnt seem to appear, i made sure bounces is greater than 0, so that it wouldnt get destroyed for 0 bounces, but still isnt appearing. There are also more than 1 enemies when i use the ability.


Fixed. I had to parent / child enemies, and change a few objects.

My issue now that objAbilitiesRicochet is created, is it works fine, it moves toward the enemy, but then upon collision it doesnt go to a different enemy. I'm thinking it's because the enemy it hits isnt getting destroyed:

When objAbilitiesRicochet hits the target enemy, the enemy loses 5hp (but the enemy has 15 and thus, wont die from 1 hit)
(That is true, if the enemy isnt destroyed the objAbilitiesRicochet will start spinning rapidly around teh target enemy. Also i'd like to note that when i changed the collision with enemy parent, and changed the health to destroy the enemy, objAbilitiesRicochet doesnt go to a nearby enemy, but it seems to head towards random enemies, no matter the distance.)

Edited by Faultekaiser, 18 February 2012 - 05:25 AM.

  • 0

#8 rude guss

rude guss

    GMC Member

  • GMC Member
  • 236 posts

Posted 18 February 2012 - 05:59 AM

Show me the code you're using please.

Edited by rude guss, 18 February 2012 - 06:00 AM.

  • 0

#9 Bladestorm Games

Bladestorm Games

    GMC Member

  • GMC Member
  • 319 posts
  • Version:GM8

Posted 18 February 2012 - 06:41 AM

Show me the code you're using please.


objAbilitiesRicochet (the actual blade)
CREATE EVENT
image_speed = 1
direction = 0
speed = 6
alarm[1] = 5
bounces =  3 //global.ability_tree_ricochet
target = noone
targetable_obj = objBasicParentEnemy


STEP EVENT
speed += 0.15
if (bounces==0)
{
    instance_destroy();
}

if (instance_exists(target))
{
    if (distance_to_object(target)>=0)
    {
        move_towards_point(target.x,target.y,speed)
    }
    else
    {
        bounces -= 1;
        with(target)
            {
                enemy_hp -= 5
                speed -= 0.5
            }
        instance_deactivate_object(target);
        tmp_nrst = instance_nearest(x,y,targetable_obj);
        instance_activate_object(target);
        target = tmp_nrst;
    }
}
else
{
    instance_destroy();
}

if speed > 5
    then
    {
        speed = 5
    }

COLLISION WITH: objBasicParentEnemy
instance_destroy()

ALARM 1
instance_create(x,y,objAbilitiesRicochetShadow)
alarm[1] = 2

Is that good?
  • 0

#10 rude guss

rude guss

    GMC Member

  • GMC Member
  • 236 posts

Posted 18 February 2012 - 07:28 AM

Okay, I think I have found the problem, revert your code to back when the objecct would go towards the enemy and just spin around them. Now change the following - "if (distance_to_object(target)>=0)" to "if (distance_to_object(target)>0)" and that should fix it.
  • 0

#11 Bladestorm Games

Bladestorm Games

    GMC Member

  • GMC Member
  • 319 posts
  • Version:GM8

Posted 18 February 2012 - 08:06 AM

Okay, I think I have found the problem, revert your code to back when the objecct would go towards the enemy and just spin around them. Now change the following - "if (distance_to_object(target)>=0)" to "if (distance_to_object(target)>0)" and that should fix it.

Now for some reason it will do damage to all summoned enemies instead of the one hit. but it stops spinning rapidly
  • 0

#12 rude guss

rude guss

    GMC Member

  • GMC Member
  • 236 posts

Posted 18 February 2012 - 08:18 AM

Don't know, might be the for(target) you are using, try removing that.try:

target.enemyhp-=999;//or whatever

  • 0

#13 Bladestorm Games

Bladestorm Games

    GMC Member

  • GMC Member
  • 319 posts
  • Version:GM8

Posted 18 February 2012 - 12:30 PM

Don't know, might be the for(target) you are using, try removing that.try:

target.enemyhp-=999;//or whatever

It still destroys all instances of enemies, and if there are 2 or more blades those blades get destroyed as well (blade = objAbilitiesRicochet)
  • 0

#14 Bladestorm Games

Bladestorm Games

    GMC Member

  • GMC Member
  • 319 posts
  • Version:GM8

Posted 22 February 2012 - 07:49 AM

48+ hour bump,
  • 0

#15 Dylan93

Dylan93

    GMC Member

  • GMC Member
  • 867 posts
  • Version:GM8

Posted 22 February 2012 - 05:00 PM

Giving a GMK for problems like this will solve the problem a thousand times quicker, if you don't want you're game to get stolen or whatever remove everything that isn't needed for the problem...
  • 0

#16 Bladestorm Games

Bladestorm Games

    GMC Member

  • GMC Member
  • 319 posts
  • Version:GM8

Posted 25 February 2012 - 06:05 AM

Giving a GMK for problems like this will solve the problem a thousand times quicker, if you don't want you're game to get stolen or whatever remove everything that isn't needed for the problem...

k I have uploaded the gmk file:
http://www.mediafire...vdud6lo5pk6k019
  • 0

#17 rude guss

rude guss

    GMC Member

  • GMC Member
  • 236 posts

Posted 25 February 2012 - 06:53 AM

Why was it damaging ALL the enemies? Because you were targeting the parent object :/. Go to objAbilityRicochetCreating and go to line 2 of Animation end event and replace it with:

ric.target = instance_nearest(x,y,objBasicParentEnemy);


So the lesson here is that it wasn't the code that you were given that had the problems, rather it was the code that you wrote yourself. You probably spent all you time trying to find the problem with the code that you were given that you ignored looking at your own code for problems.

Edited by rude guss, 25 February 2012 - 06:55 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users