How to do a Ricochet?
#1
Posted 17 February 2012 - 04:25 AM
Could someone help me out with that? Thanks!
#2
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.
#3
Posted 17 February 2012 - 04:43 AM
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.
#4
Posted 18 February 2012 - 02:47 AM
#5
Posted 18 February 2012 - 02:53 AM
You must wait 48 hours before double posting.Does anyone else have a good ricochet system?
Also, what's wrong with the one that rude guess has supplied you with?
#6
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
#7
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
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.
#8
Posted 18 February 2012 - 05:59 AM
Edited by rude guss, 18 February 2012 - 06:00 AM.
#9
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?
#10
Posted 18 February 2012 - 07:28 AM
#11
Posted 18 February 2012 - 08:06 AM
Now for some reason it will do damage to all summoned enemies instead of the one hit. but it stops spinning rapidlyOkay, 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.
#12
Posted 18 February 2012 - 08:18 AM
target.enemyhp-=999;//or whatever
#13
Posted 18 February 2012 - 12:30 PM
It still destroys all instances of enemies, and if there are 2 or more blades those blades get destroyed as well (blade = objAbilitiesRicochet)Don't know, might be the for(target) you are using, try removing that.try:
target.enemyhp-=999;//or whatever
#14
Posted 22 February 2012 - 07:49 AM
#15
Posted 22 February 2012 - 05:00 PM
#16
Posted 25 February 2012 - 06:05 AM
k I have uploaded the gmk file: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...
http://www.mediafire.com/?vdud6lo5pk6k019
#17
Posted 25 February 2012 - 06:53 AM
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 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











