Jump to content


Photo

Auto Aiming


  • Please log in to reply
12 replies to this topic

#1 AlexTM

AlexTM

    GMC Member?

  • GMC Member
  • 1422 posts
  • Version:GM8

Posted 30 May 2012 - 04:23 PM

Hi. I've sucessfully made an Auto aim system for a top down game. However, the auto-aim object only sticks to the pedestrian that I'm aiming at. Which is good but I want to add something else.

How can I make it so if i move the mouse a little, the aim object will still stick to the pedestrian but move slightly so that I can shoot other parts of the body?

Like it sticks to the pedestrian but I can only move it like 32 steps away from the pedestrian.
How do i do this?

Information on the OBJ_MOUSE object:
Spoiler

Edited by A!ex, 30 May 2012 - 05:06 PM.

  • 0

#2 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1460 posts
  • Version:GM:Studio

Posted 30 May 2012 - 04:36 PM

you need to upload your current one as we will be coding blind and most likely break your current one or just not get it to work
  • 0

#3 AlexTM

AlexTM

    GMC Member?

  • GMC Member
  • 1422 posts
  • Version:GM8

Posted 30 May 2012 - 05:06 PM

Spoiler


  • 0

#4 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1460 posts
  • Version:GM:Studio

Posted 30 May 2012 - 05:16 PM

i dont see any auto amining there i may be blind. plz explain it or wait for someone else to spot it and help you
  • 0

#5 AlexTM

AlexTM

    GMC Member?

  • GMC Member
  • 1422 posts
  • Version:GM8

Posted 30 May 2012 - 05:53 PM

i dont see any auto amining there i may be blind. plz explain it or wait for someone else to spot it and help you


yeayea I realised that 10 minutes ago. The auto-aiming code is in the characters right mouse button event.
This is the code:

with(OBJ_MOUSE) {if obj_player.weapon_equip!=4 and distance_to_object(obj_player)<=300
{x=instance_nearest(x,y,obj_peds).x
y=instance_nearest(x,y,obj_peds).y
global.auto_aim=1}}

with(OBJ_MOUSE) 
{if distance_to_object(obj_player)>300
{global.auto_aim=0}}

if weapon_equip=4
{view_object[view_current]=OBJ_MOUSE}

  • 0

#6 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1460 posts
  • Version:GM:Studio

Posted 31 May 2012 - 12:38 AM

ok just add

a check for mouse position if its currently over a body part(if your locking on to body parts) else just let the mouse freely target within the object(ie locks on, but if mouse is within the sprite target that spot).
im tired atm so if you cant work out how to do it, please work out exactly how you want it to work and maybe a picture and ill give you a hand.
  • 0

#7 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14395 posts
  • Version:GM:Studio

Posted 31 May 2012 - 01:42 AM

I think your code should be in the mouse object...

Asuming you currently have
x = mouse_x;
y = mouse_y;

this should snap to a obj_ped
//follow mouse
x = mouse_x;
y = mouse_y;
//stop here, if auto-aim is off
if(global.auto_aim==0) exit;

//snap to ped? find a ped
var ins;
ins = instance_nearest(x, y, obj_peds)
if (ins != noone)
{
    //distance to ped
    var d;
    d = point_distance(ins.x, ins.y, x, y);
    //within snap 300 is way to big but I have no idea for you game. I would use the ped radius
    var maxd;
    maxd = 300;
    //maxd = point_distance(ins.bbox_left, ins.bbox_top, ins.bbox_right, ins.bbox_bottom) / 2;
    //snap on ped, but not right on it. On ped within the snap radius
    if (d <= maxd)
    {
        var a;
        a = point_direction(ins.x, ins.y, x, y);
        x = ins.x + lengthdir_x(median(0, maxd, d), a);
        y = ins.y + lengthdir_y(median(0, maxd, d), a);
    }
}

[edit] fixed up point_distance and point_direction
  • 0

#8 AlexTM

AlexTM

    GMC Member?

  • GMC Member
  • 1422 posts
  • Version:GM8

Posted 31 May 2012 - 06:24 AM

That didn't work :unsure:
  • 0

#9 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14395 posts
  • Version:GM:Studio

Posted 31 May 2012 - 07:16 AM

That didn't work :unsure:


It would help to be more specific
  • 0

#10 AlexTM

AlexTM

    GMC Member?

  • GMC Member
  • 1422 posts
  • Version:GM8

Posted 31 May 2012 - 03:28 PM

Doesn't even aim to anything. Just follows the mouse completely.
  • 0

#11 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14395 posts
  • Version:GM:Studio

Posted 31 May 2012 - 05:47 PM

Maybe you did not change maxd like said... the commented out maxd
  • 0

#12 AlexTM

AlexTM

    GMC Member?

  • GMC Member
  • 1422 posts
  • Version:GM8

Posted 31 May 2012 - 08:22 PM

Maybe you did not change maxd like said... the commented out maxd


ye I changed maxd to 48
  • 0

#13 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1460 posts
  • Version:GM:Studio

Posted 31 May 2012 - 08:44 PM

im pretty sure its this bit
//follow mouse
x = mouse_x;
y = mouse_y;

and 
if (d <= maxd)
not doing all situations you want. you want if the mouse is no where near the object that it follows mouse(or disapears?) if its withing a certain distance it locks on, if it is within the sprite it manually aims a little.

you need another bit then
//follow mouse
xx = mouse_x;
yy = mouse_y;
//stop here, if auto-aim is off
if(global.auto_aim==0) 
{
x=xx;
y=yy;
exit;
}

//snap to ped? find a ped
var ins;
ins = instance_nearest(xx,yy, obj_peds)
if (ins != noone)
{
    //distance to ped
    var d;
    d = point_distance(ins.x, ins.y, xx, yy);
    //within snap 300 is way to big but I have no idea for you game. I would use the ped radius
    var maxd;
    maxd = 48;
    //maxd = point_distance(ins.bbox_left, ins.bbox_top, ins.bbox_right, ins.bbox_bottom) / 2;
    //snap on ped, but not right on it. On ped within the snap radius
    if (d <= maxd*2)
    {
        var a;
        a = point_direction(ins.x, ins.y, xx, yy);
        x = ins.x + lengthdir_x(median(0, maxd, d), a);
        y = ins.y + lengthdir_y(median(0, maxd, d), a);
    }
}

i think that will do what you want? if i understood the code(i dont have access to GM atm to test). i made it so the aim obj only follows the mouse directly if its within the sprite OR outside the range for auto aim(i put 2*mxd, as i think maxd is the sprite size? or half, so i thought youd want the mouse to lock on outside of the sprite). i think thats it... else his code needs to be changed
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users