Jump to content


Photo

Problem with Shooting


  • Please log in to reply
4 replies to this topic

#1 BigJayMalcolm

BigJayMalcolm

    GMC Member

  • New Member
  • 1 posts

Posted 05 January 2011 - 03:40 PM

I am creating a game which involves shooting arrows. But i want to know how i can check which direction i am facing to fire which arrow (I have 4 arrow objects, Up, Down, Left and Right)

If anyone could help with how to do it, That would be much appreciated :)
  • 0

#2 batlord

batlord

    GMC Member

  • GMC Member
  • 130 posts

Posted 05 January 2011 - 05:33 PM

I am creating a game which involves shooting arrows. But i want to know how i can check which direction i am facing to fire which arrow (I have 4 arrow objects, Up, Down, Left and Right)

If anyone could help with how to do it, That would be much appreciated :)


Create Event:
dire = "";

keypress right:
dire = "right";

keypress left:
dire = "left";

keypress up:
dire = "up";

keypress down:
dire = "down";

Keypress Ctrl:
if (dire == "right")
  instance_create(x,y,obj_arrow_right)
else if (dire == "left")
  instance_create(x,y,obj_arrow_left)
else if (dire == "up")
  instance_create(x,y,obj_arrow_up)
else if (dire == "down")
  instance_create(x,y,obj_arrow_down)

  • 0

#3 loverock125

loverock125

    GMC Member

  • GMC Member
  • 1606 posts
  • Version:GM8

Posted 05 January 2011 - 06:43 PM

I am creating a game which involves shooting arrows. But i want to know how i can check which direction i am facing to fire which arrow (I have 4 arrow objects, Up, Down, Left and Right)

If anyone could help with how to do it, That would be much appreciated :)



What batlord said will work. However if you have pro edition then you can use 'direction' and 'image_angle'.
  • 0

#4 Davido01

Davido01

    GMC Member

  • New Member
  • 905 posts

Posted 05 January 2011 - 06:53 PM

Also there is no need to have 4 arrow objects, its more trouble than what its worth.

This would be better IMO:

if (dire == "right")
{
  var obj;
  obj=instance_create(x,y,obj_arrow);
  with (obj) motion_set(0,4);
}
else if (dire == "left")
{
  var obj;
  obj=instance_create(x,y,obj_arrow);
  with (obj) motion_set(180,4);
}
else if (dire == "up")
{
  var obj;
  obj=instance_create(x,y,obj_arrow);
  with (obj) motion_set(90,4);
}
else if (dire == "down")
{
  var obj;
  obj=instance_create(x,y,obj_arrow);
  with (obj) motion_set(270,4);
}

More lines of code but you don't need to maintain 4 objects.
  • 0

#5 _175023

_175023

    GMC Member

  • New Member
  • 46 posts

Posted 05 January 2011 - 07:11 PM

...and if you have pro, add to each with statement 'obj.image_angle = 0' or 180 or whatever direction it is facing. The non-pro way would be to make the arrow object have four sprites, one for each direction and then do 'obj.sprite_index = 360/obj.direction'

Also there is no need to have 4 arrow objects, its more trouble than what its worth.

This would be better IMO:

if (dire == "right")
{
  var obj;
  obj=instance_create(x,y,obj_arrow);
  with (obj) motion_set(0,4);
}
else if (dire == "left")
{
  var obj;
  obj=instance_create(x,y,obj_arrow);
  with (obj) motion_set(180,4);
}
else if (dire == "up")
{
  var obj;
  obj=instance_create(x,y,obj_arrow);
  with (obj) motion_set(90,4);
}
else if (dire == "down")
{
  var obj;
  obj=instance_create(x,y,obj_arrow);
  with (obj) motion_set(270,4);
}

More lines of code but you don't need to maintain 4 objects.


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users