Jump to content


Zinth

Member Since 14 Apr 2012
Offline Last Active May 03 2012 08:53 PM

Posts I've Made

In Topic: NPC sprite change based on direction and movement

15 April 2012 - 05:07 AM

Got my code working now with full animation change and everything just had to make my own variable and set it several times in the code depending on the situation. Called the variable current_speed. Also discovered I can combine all my code into one script which made it easier to manage.

// varaibles
var follow_obj;
var kill_obj;
var current_speed;

follow_obj = TargetObj
kill_obj = HumanParent_obj
current_speed = 0

// set up move to target code
if (instance_exists(follow_obj))

{

 mp_potential_settings(90,90,3,false);

 mp_potential_step_object(follow_obj.x, follow_obj.y, 3, ZM1Obj);

 direction = round(direction/90)*90;
 
 current_speed = 3
 
 if (distance_to_object(follow_obj) <= 2)

 {
    current_speed = 0
    
   x = xprevious;

   y = yprevious;

 }
 

}

// set up move to human code
if (instance_exists(kill_obj))
{
    if (distance_to_object(kill_obj) <= 20)
    {
        if !(collision_line(x,y,kill_obj.x,kill_obj.y,Wall_obj,false,true))
        {
        
            mp_potential_settings(90,90,3,false);

            mp_potential_step_object(follow_obj.x, follow_obj.y, 3, ZM1Obj);

            direction = round(direction/90)*90;
            
            current_speed = 3
        }
    }
}

// set up movement system
if (current_speed > 0 )
{
    if (direction >= 45 && direction < 135)
    {
        sprite_index = ZM1Up;
    }
    else if (direction >= 135 && direction < 225)
    {
        sprite_index = ZM1Left;
    }
    else if (direction >= 225 && direction < 315)
    {
        sprite_index = ZM1Down;
    }
    else
    {
    sprite_index = ZM1Right;
    }
}
else
{
    if (direction >= 45 && direction < 135)
    {
        sprite_index = ZM1UpStill;
    }
    else if (direction >= 135 && direction < 225)
    {
        sprite_index = ZM1LeftStill;
    }
    else if (direction >= 225 && direction < 315)
    {
        sprite_index = ZM1DownStill;
    }
    else
    {
    sprite_index = ZM1RightStill;
    }
}

now to figure out collision coding and get my human hunter code working and my zombies will be done :D

In Topic: NPC sprite change based on direction and movement

15 April 2012 - 03:14 AM

I found some code in one of the tutorials and have mixed it with some of my own to get a semi decent moving to target AI going and I fixed the movement problem

go to AI
var follow_obj;

follow_obj = TargetObj

if (instance_exists(follow_obj))

{

 mp_potential_settings(90,90,3,false);

 mp_potential_step_object(follow_obj.x, follow_obj.y, 3, ZM1Obj);

 direction = round(direction/90)*90;
 if (distance_to_object(follow_obj) <= 2)

 {

   x = xprevious;

   y = yprevious;

 }
 

}

Sprite Change based on movements and direction
if (speed > 0 )
{
    if (direction >= 45 && direction < 135)
    {
        sprite_index = ZM1Up;
    }
    else if (direction >= 135 && direction < 225)
    {
        sprite_index = ZM1Left;
    }
    else if (direction >= 225 && direction < 315)
    {
        sprite_index = ZM1Down;
    }
    else
    {
    sprite_index = ZM1Right;
    }
}
else
{
    if (direction >= 45 && direction < 135)
    {
        sprite_index = ZM1UpStill;
    }
    else if (direction >= 135 && direction < 225)
    {
        sprite_index = ZM1LeftStill;
    }
    else if (direction >= 225 && direction < 315)
    {
        sprite_index = ZM1DownStill;
    }
    else
    {
    sprite_index = ZM1RgihtStill;
    }
}



I got some tweaks to make yet as I also want these things to hunt other-things unless given an order.

I hope this helps with anyone who had similar problems that I had, and thanks for all the help greep your a life saver.

Edit: Never mind about it fixing the movement animation I just switched my sprites to rpgmaker xp style using My link to make sprites and it doesn't work, got to find a new way to do it.

In Topic: NPC sprite change based on direction and movement

14 April 2012 - 08:56 PM

Ok thanks I will try just doing all the things in GML code so I can see whats happening better, and I think its good practice to do it that way anyways. I just hadn't before because I didn't know if I wanted to go that in-depth into this game but I will and use it as a way to learn GML instead of just using GML as patchwork for the things I can't do in D&D.

In Topic: NPC sprite change based on direction and movement

14 April 2012 - 02:56 PM

Well that worked awesomely thanks, My zombies now face the right direction when moving however got another problem. I can't seem to get it to detect speed so I can make the walking animation work when moving and it be still when not. Right now I get the still facing the right direction and hovering towards the object.

Things I've tried

if (direction => 45 && direction < 135 && vspeed > 0 )
{
sprite_index ZM1Up;
}

I just thought of something in a room is up +# and down -# or is it the other way around for the y axis.

but then I tried


if (direction => 45 && direction < 135 && speed >0)
{
sprite_index ZM1Up;
}

and still nothing. I tried looking up ways of detecting speed and what I found is current_speed, but when I type that in it doesn't have a built in variable for it.
also I've tried putting it at beginning of step, end of step and nothing.

I'm going to keep trying but any more awesome tips and advice would be much appreciated.

In Topic: NPC sprite change based on direction and movement

14 April 2012 - 06:25 AM

Well which would you prefer, 4 directional pathfinding, or fix your sprites for diagonal? The latter is actually very easy, the former is kinda difficult depending on the game.

Well the game I'm trying to make is a zombie hybrid were you are a zombie and have the ability to set a location were the more mindless zombies in the area will go to attack, I got the target set to create with a mouse click and they move there (no walls yet just an empty room) but its ugly, I don't mind them moving in diagonals I would just like them to have the right direction sprite when moving and I'm using rpgmaker 2003 sprites so I'm stuck with a 4 directional look (I'm not an artist, and only a beginner programmer just have several game designs in my mind).

So to answer this more clearly I don't mind Diagonals if there's a way to fix the sprites. I like the idea of the zombies running into walls to get to the target and half the game is about getting them to follow your directions. Though I would love to see an example of code on 4 directional path-finding if you know of one for future reference as that might come in handy for the humans I plan on putting in.

And thanks for the quick reply :D