Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411618 Posts in 69390 Topics- by 58447 Members - Latest Member: sinsofsven

May 10, 2024, 12:31:45 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Game Maker 7 - Targetting discreet units/object ids
Pages: [1]
Print
Author Topic: Game Maker 7 - Targetting discreet units/object ids  (Read 1774 times)
Destral
Level 10
*****


Climbing that mountain...


View Profile WWW
« on: December 10, 2009, 01:38:04 AM »

Hi again folks. I have another question:

In the game I'm working on, the player spawns units that move towards the left edge of the screen towards a target. The target also spawns units that make their way towards the player. The target units and the player units meet in the middle and fight. I'm using inheritance to give the units the fighting behaviour - each unit checks if there is a unit of the opposing faction in front of it, and if there is, a timer goes off every second or so that reduces the enemy unit's health.

The problem I'm encountering is that the damage is being dealt to ALL units in front, instead of just one. I was talking to a friend who also has some Game Maker experience, and he was saying that I should use objectid to give each unit object it's own identity, and use that to assign damage to a single unit. Does anyone know how I could go about it? This is my event/action list so far:



(Even that version doesn't work, because there it is checking whether there is something in front of it, but when trying to change the 'humHealth' variable in the 'other', there is no 'other' defined. Changing that to a collision works, until there is more than one enemy in collision with the unit).

Any help would be greatly appreciated! Gentleman
Logged

Currently working on: Sword Surfer
Tycho Brahe
Level 10
*****

λx.x


View Profile
« Reply #1 on: December 10, 2009, 03:19:38 AM »

Could you have some way of looping through all the units in front if it and checking which has the closest x-value? This may not be the best way in gamemaker but I would do it this way usually
Logged
ChevyRay
Guest
« Reply #2 on: December 10, 2009, 03:45:44 AM »

I would highly recommend learning and using GML code for this Smiley You can accomplish the exact same thing you're doing there with something like this:

Code:
if (uHealth < 1)
{
instance_destroy();
}
else
{
var collidingWith;
collidingWith = instance_place(x, y, object);

if (collidingWith)
{
direction = 180;
speed = 2;

if (uAttackDelay < 1)
{
collidingWith.humHeath = uAttackPower;
uAttackDelay = uAttackDelayMax;
}
else
{
uAttackDelay = -1;
}
}
else
{
direction = 0;
speed = 2;
}
}

I replaced "Start moving in a direction" with two lines that just set the direction and speed, and will do the exact same thing (the direction variable is 0 for right, and counts up counter-clockwise in degrees).

This particular code is not working because, like you say, other is unnasigned. In the code I've shown you above, I use a function called instance_place to check (x, y) for (object), and assign the resulting object ID value to a variable called collideWith. Now, in all the following lines, I am able to use collideWith to refer to that particular instance that I collided with, not none or all of them.

GML in particular isn't much harder to use than drag and drop, and is much more maintainable. You can see how { and } are equivalent to the start and end-block events, and you can use if and else statements, etc. to set the conditions for those code blocks.

I don't know the drag and drop functions that well, so I can't help you more than that. Good luck with your game Smiley
Logged
Destral
Level 10
*****


Climbing that mountain...


View Profile WWW
« Reply #3 on: December 10, 2009, 08:08:18 AM »

Thanks ChevyRay, I'll give that a shot tonight.  Gentleman
Logged

Currently working on: Sword Surfer
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic