Jump to content


Photo

100mph bullets/AI moving?


  • Please log in to reply
7 replies to this topic

#1 SuperNESFreak

SuperNESFreak

    GMC Member

  • New Member
  • 32 posts

Posted 26 January 2011 - 07:23 PM

Hi GMC,

I'm working on a stealth/action shooter game a bit like Counter Strike 2D meets Metal Gear. I have a few problems:

1) Enemy Moving

I use the Step Avoiding code to make the computer players move towards their target. The problem is that the computers are brain dead. If they have a wall in the way of their target, they just keep ramming into it. These tight corners are essential as the map is a Dilert-esque office. The code is:

if not priority = 2 or point_distance(x,y,targetx,targety) > 25 then {
mp_potential_step_object(targetx,targety,priority,object_solid)
image_speed = priority/3 }

Also, I make the enemies always look towards their objective, but it would be really good if they were actually looking where they were going. I can't do this using the 'direction' variable since the enemies use steps. Is there another way of doing this?

2) Bullets

I want the bullets, instead of being dots, to be lines that instantly fire off and stop at the first solid they meet. Is there a way to do this?

Thanks very much.
  • 0

#2 Uniquebum

Uniquebum

    GMC Member

  • New Member
  • 317 posts

Posted 26 January 2011 - 07:36 PM

Sounds like they aren't considering the walls, as objects. Make sure object_solid is actually solid and that the wall object's have this as their parent.

For the direction

direction = point_direction(xprevious, yprevious, x, y);



  • 0

#3 M_I_Soft

M_I_Soft

    GMC Member

  • GMC Member
  • 198 posts
  • Version:GM8

Posted 26 January 2011 - 07:36 PM

I've found some problems before using a specific object to avoid.
I ended up using mp_potential_step(xs,ys,2,solid) instead - that way anything that was solid got avoided.
Might work for you, but might not...

The bullets I did by having a 16x2 sprite for the bullet and the following code in it's object..

Create Event
speed=32;                    // nice and quick
direction=image_angle;       // make sure it's going in the direction you're shooting in
image_xscale=random(1);      // set the scale to be slightly random - that way you get a 
image_yscale=random(1)+0.5;  // smoother effect with the faster bullets


Step Event
image_xscale=image_xscale+.5
// so basically the longer it's in the room, the longer it's going to get
// - this is important for the collisions at these sort of speeds!

Collision with solid Event
instance_destroy();          // we've contacted the solid so let's disappear

Draw Event
// set the direction to make sure the angle of the bullet is correct at all 
// times then draw the sprite to the screen
image_angle=direction;
draw_sprite_ext(sprite_index,image_index,round(x),round(y),image_xscale,image_yscale,image_angle,c_white,1);

There's a bit more to the bullet code that I use with the use of muzzle flash and debris when you hit a solid but that should give you a bullet that starts off small and stretches as it gets further away to give a much greater impression of speed.
You can see it in action in my current WIP, Haunted Mansion in my signature.

Leigh

Edited by lwindridge, 26 January 2011 - 07:46 PM.

  • 0

#4 SuperNESFreak

SuperNESFreak

    GMC Member

  • New Member
  • 32 posts

Posted 27 January 2011 - 04:43 PM

Thanks. The bullets are looking really good and the enemy movement is nice and fluid, but I think I've scuffed his AI code. Now he won't respond to distractions at all and he barely notices the player even when I'm right in front of him! A little testing reveals the enemy only 'sees' the player if he is exactly on his Y and is to the right of him.

depth=w3d_depth(x,y,z)
image_speed = 0
distraction = instance_nearest(x,y,object_distraction)
if instance_number(object_noisedistraction) > 0
then distraction = instance_nearest(x,y,object_noisedistraction)
if priority = 1 then
    {
    targetx = objective.x
    targety = objective.y
    if point_distance(x,y,objective.x,objective.y) < 30 then objective = instance_furthest(x,y,object_aiobjective)
    }
if not priority = 3 then
    {
    if point_distance(x,y,distraction.x,distraction.y) < 160 and distraction.on = 1 then
        {
        if not priority = 2 then {
            sign = instance_create(x,y,object_animation)
            sign.sprite_index = sprite_questionmark
            }
        priority = 2
        targetx = distraction.x
        targety = distraction.y
        }
    }
if priority = 2 then
    {
    if point_distance(x,y,targetx,targety) < 30 then
        {
        distraction.on = 0
        }
    if distraction.on = 0 then priority = 1
    }
if collision_line(x,y,object_player.x,object_player.y,object_solid,0,1) < 0
and point_direction(x,y,object_player.x,object_player.y) < image_angle + 90
and point_direction(x,y,object_player.x,object_player.y) > image_angle - 90 then
    {
    if not priority = 3 then {
        sign = instance_create(x,y,object_animation)
        sign.sprite_index = sprite_exclamationmark
        }
    priority = 3
    global.alert = 1
    alarm[2] = 150
    targetx = object_player.x
    targety = object_player.y
    }
if not priority = 2 or point_distance(x,y,targetx,targety) > 25 then {
mp_potential_step_object(targetx,targety,priority,object_solid)
image_speed = priority/3 }

I think the main problems are in seeing the player and deciding what the enemy is currently doing: patrolling, checking out a distraction or chasing the player.

Edited by SuperNESFreak, 27 January 2011 - 04:52 PM.

  • 0

#5 Gibraldi

Gibraldi

    GMC Member

  • New Member
  • 340 posts

Posted 27 January 2011 - 04:50 PM

if not priority = 3 then


are you sure that is correct?
  • 0

#6 SuperNESFreak

SuperNESFreak

    GMC Member

  • New Member
  • 32 posts

Posted 27 January 2011 - 05:02 PM

Wow, that was stupid of me. I was telling the game to use image_angle when I wasn't using the variable (instead telling the enemy which way to point in the draw event).

That's that problem solved, but I'm still stumped on the priorities.
  • 0

#7 SuperNESFreak

SuperNESFreak

    GMC Member

  • New Member
  • 32 posts

Posted 27 January 2011 - 05:06 PM

if not priority = 3 then


are you sure that is correct?


Yes. The enemy won't be distracted by gunfire, radios or TVs if he's seen the player.

Sorry for double posting, but I've noticed something else. Probably because I'm using the w3d engine, bullets very often go through walls, unless they hit them bang in the center.
  • 0

#8 Gibraldi

Gibraldi

    GMC Member

  • New Member
  • 340 posts

Posted 27 January 2011 - 08:12 PM

yes but not equal to 3 is the same as equal to one, or two, or four
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users