• 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!

3D Enemie AI random movement not working outside room (solved)

Fredrik

Member
Hello!

I'm making a 3D game, so the game doesnt necessarily take place intside the room. Most of the game actually takes place outside the defined room size.
In the enemy's AI they will "idle walk" around when not aggro towards the players. The code looks like this:

GML:
// Idle walking.
if stunned = 0
    {if enemiewalk = 2
        {
        idletimer += 1;
        if idletimer = 100
            {
            randomize();
            idletimer = 0;
            idlex     = irandom(360);
            idley     = irandom(360);
            }

        mp_potential_step_object(idlex,idley,spd,parent_solid);
        }
    }
This works completly fine, as long as the enemy is inside the room borders. But if it's outside it will always move towards the room borders before it actually start moving in random directions. Why is that? :/
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
I'm not sure what you have originally envisioned this irandom(360) to be, but you are simply picking a random point in (0,0) - (360,360) space, so yes, this does not work as expected for negative or higher coordinates as the instance will simply try moving back into that area (and probably fail since mp_potential_step_object lacks foresight).
Perhaps you'd want
Code:
    idlex     = xstart + irandom_range(-180, 180);
    idley     = ystart + irandom_range(-180, 180);
or a use irandom(360) as an angle and use lengthdir_x/y
 

Joe Ellis

Member
It's definitely the mp_potential_step_object, that must need to be in the room, it must make the navgrid inside the room, so if it's outside it'll have it's target point somewhere along the borders of the room.
I dunno what to suggest other than not use that, and make something similar.. Heck, I set the room_width\room_height to the screen res and then use them as a fast\global way to do stuff that involves the width\height of the screen
Rooms have no use if the game is 3d, other than that handy thing of instead of using global.screen_width and global.screen_height, you can use room_width and room_height, and it's very slightly faster, but mainly easier to type lol
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
It's definitely the mp_potential_step_object, that must need to be in the room, it must make the navgrid inside the room, so if it's outside it'll have it's target point somewhere along the borders of the room.
I dunno what to suggest other than not use that, and make something similar.. Heck, I set the room_width\room_height to the screen res and then use them as a fast\global way to do stuff that involves the width\height of the screen
Rooms have no use if the game is 3d, other than that handy thing of instead of using global.screen_width and global.screen_height, you can use room_width and room_height, and it's very slightly faster, but mainly easier to type lol
mp_potential_step_object does not use any kind of navgrid. See the manual for more information: http://docs2.yoyogames.com/source/_...ns/motion planning/mp_potential_settings.html
 

Joe Ellis

Member
Ah, I'll pass haha, thanks though
That said, it's still cus of mp_potential_step_object cus nothing else would affect it (in that involuntary kind of way)
 
Last edited:

Fredrik

Member
Thanks for the replies, I found out, as also YellowAfterlife points out, that my code made it pick a random x and y position of irandom(360), while my intention was for it to choose a random direction of irandom(360), this has since been resolved in another way.
So this was a mistake from my side.
 
Top