Jump to content


Photo

Can someone download my game? need tips


  • Please log in to reply
4 replies to this topic

#1 jagkallasfrags

jagkallasfrags

    GMC Member

  • New Member
  • 63 posts

Posted 30 November 2011 - 07:39 AM

Hello, I want to have like some enemys on my game, but I have no idea of how I should do or how to get them to walk automaticly and attack obj_char(the character) if he gets to close to the enemys. I have 2 bots on my game right now but they only bounces between 2 objects.
Here is the download link so you can see how the game is:
http://www.2shared.c...VbLB/DEMO3.html

Walk on "WASD" punch on "left click" pick up items on "shift"

hope you can help. and if you got an idea you will probably have to help me make it (if you can) becouse I am not so good on gamemaker yet.

Hope you like it.
  • 0

#2 jagkallasfrags

jagkallasfrags

    GMC Member

  • New Member
  • 63 posts

Posted 03 December 2011 - 10:33 AM

So, no one?
  • 0

#3 icymx

icymx

    Patrick Brett

  • GMC Member
  • 790 posts
  • Version:GM8

Posted 03 December 2011 - 10:45 AM

I might check over it tomorrow if there are replies by then. And if I forget, don't worry - there are loads of other people more than willing to help, they just might not have seen your topic yet.
  • 0

#4 Noele

Noele

    GMC Mentor

  • GMC Member
  • 2351 posts
  • Version:GM8.1

Posted 03 December 2011 - 11:49 AM

Tried it but the download is to an exe which sparked a security alert and and promptly got removed after downloading.

If you need tips on creating your enemies movements take a look in the tutorial forums for AI movement and also using Paths and Timelines.

A path is a predefined route you plot which you can allocate to an instance to have it follow. You can create multiple paths, swapping them and even create them dynamically.

A timeline is simply a container into which you place actions which must be done at certain moments (steps).
From the manual:

Assume you want to make a guard. This guard should move 20 time steps to the left, then 10 upwards, 20 to the right, 10 downwards and then stop. To achieve this you make a time line where you start with setting a motion to the left. At moment 20 you set a motion upward, at moment 30 a motion to the right, at moment 50 a motion downwards and at moment 60 you stop the motion. Now you can assign this time line to the guard and the guard will do exactly what you planned.


For more complex AI systems (for bosses and such) you can also use grid based movements but these use some advanced functions.
  • 0

#5 RubixCube

RubixCube

    GMC Member

  • New Member
  • 47 posts

Posted 03 December 2011 - 12:29 PM

I can help with the enemies, but can I see your movement code? It seems the character stops whenever you let go of a direction. It really breaks up the walking if you want to move a little bit left or right and you have to let go of up press left or right, and then press up again.

As for the enemies use the distance formula from algebra 1.
Put this into an enemy's step event, and the enemy will always know how far it is from the character.

Then you can do something like this in the step event.

distance = power((power(x-obj_char.x,2) + power(y-obj_char.y,2)),(1/2)); //distance formula
walkSpeed = 4; //whatever speed you want the enemy to have
if (distance < 100) //depends on how far away you want the enemy to see the character
{
    //decides whether the character walks left/right or up/down first. 
    if (boolean)
    {
        if (x > obj_char.x + walkSpeed) //needs + walkSpeed because the enemy won't always land on the exact pixel that your character is on
        {
            // if it's less then a certain number, the enemy should stop walking and attack
            if (distance < 20)
            {
                //put an if (not facing left) {face left;} here
                
                //attack character
            }
            else
            {
                x -= walkSpeed;
            }
        }
        else if (x < obj_char.x - walkSpeed)
        {
            // if it's less then a certain number, the enemy should stop walking and attack
            if (distance < 20)
            {
                //put an if (not facing right) {face right;} here
                
                //attack character
            }
            else
            {
                x += walkSpeed;
            }
        }
        else
        {
            boolean = !boolean;
        }
    }
    else
    {
        if (y > obj_char.y+walkSpeed)
        {
            // if it's less then a certain number, the enemy should stop walking and attack
            if (distance < 20)
            {
                //put an if (not facing left) {face left;} here
                
                //attack character
            }
            else
            {
                y -= walkSpeed;
            }
        }
        else if (y < obj_char.y-walkSpeed)
        {
            // if it's less then a certain number, the enemy should stop walking and attack
            if (distance < 20)
            {
                //put an if (not facing right) {face right;} here
                
                //attack character
            }
            else
            {
                y += walkSpeed;
            }
        }        
        else
        {
            boolean = !boolean;
        }
    }
}

Inside of the enemy's create event you'll need
boolean = floor(random(2));

Including the boolean into the code makes it so the enemy doesn't always approach from the top/bottom or left/right.
walkSpeed = 4; should probably go in the create even too. You can also get rid of walkSpeed and just replace all of the x/y +=/-= stuff with whatever movement code you prefer.

Edited by RubixCube, 03 December 2011 - 12:41 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users