• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Beginner questions (moving objects towards other objects)

H

heks

Guest
Hi all,

I'm trying to learn gamemaker and make some very simple first games using various different tutorials.

I'm trying to make a very simple game around the theme of evolution where objects meet & create offspring (or eat each other).

At the moment I have two different 'creatures' wandering around the room and making eggs when they meet which create offspring (after an alarm goes off). Or, if they meet an opposing type of creature, the two creatures eat each other and the sprite becomes smaller until the creature dies.

game.png

I have a few different questions.

1) When two of the creatures collide, I have the code set to create an instance of the egg object - the problem is that this creates two eggs and it would be nice for it to create just one. Is there a simple way around this? I could just create male and female objects and only have the female ones lay eggs... but that would be cheating :)

2) At the moment the creatures just move around the room randomly and I want to make their movement more complex, but I have been having a lot of trouble with this.

I've tried to make them just move towards the player to start with to experiment.

I tried using this code from the Tom Francis tutorials:

/* Moving to others */
if State = "Idle" {

if IHaveLineOfSightTo(o_player) {
State = "Alert"
}

} else if State = "Alert" {

if IHaveLineOfSightTo(o_player) {
//Go Towards it
direction = point_direction(x,y,o_player.x,o_player.y)
} else {
State = "idle"

}
}

With the script:

Thing = argument0
Result = false

if instance_exists (Thing) {
if collision_line(x,y,Thing.x,Thing.y,0,true,true) = noone {
Result = true
}
}
return Result



I suspect their might be a problem with the states, I have State = "idle" in the creatures 'create' section. Did I need to do something else to set up the states?

Thanks for helping a beginner out!
 

Simon Gust

Member
To problem 1, both of the parents call the collision object, therefore 2 offspring is spawned. You can do a gender system or just ask the parents, which one has the higher id and let that one run the script.
 
Top