Jump to content


Photo

Platformer-Gun aim at mouse


  • Please log in to reply
6 replies to this topic

#1 Joegernaut

Joegernaut

    GMC Member

  • New Member
  • 77 posts

Posted 12 June 2011 - 07:45 AM

Ok I have two problems

Problem 1:

End step code:

if global.dir = 0{
x = Obj_Player.x+lengthdir_x(16,image_angle)
y= Obj_Player.y+lengthdir_y(-13,image_angle)}
else{
x = Obj_Player.x+lengthdir_x(16,image_angle)
y= Obj_Player.y+lengthdir_y(-13,image_angle)}

The gun's origin is at the shoulder of the arm.
This makes the gun follow the player correctly.
However, the gun is placed in the correct x position but for some reason, The y position didn't change when I wrote -13

Problem 2:

I'm not sure how to code it so that the end of the arm points towards the mouse.

This is my step code currently:

if global.dir = 0//If facing left
{
    sprite_index = Spr_Arm image_index = 0 image_speed = 0//Change sprite to arm left
}
else//If facing right
{
    sprite_index = Spr_Arm image_index = 1 image_speed = 0//change sprite to arm right
}

  • 0

#2 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16823 posts
  • Version:GM:Studio

Posted 12 June 2011 - 08:03 AM

Okay, that first problem... I see NO difference between the two parts of the code (the "if" is the same as the "else")! So maybe that's the problem? For the other part, you need to create a variable to hold the angle at which the arm points then draw the sprite using draw_sprite_ext(). For example...

//CREATE EVENT
a_angle=0;

//STEP EVENT
a_angle = point_direction(x, y, mouse_x, mouse_y);

//DRAW EVENT
draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, image_yscale, a_angle, image_blend, image_alpha);

  • 0

#3 Joegernaut

Joegernaut

    GMC Member

  • New Member
  • 77 posts

Posted 12 June 2011 - 08:53 AM

For the first problem, That doesn't make a difference but thank you for pointing that out to me.
For the second one: it works great except when I'm facing right it points in the opposite direction.
  • 0

#4 Joegernaut

Joegernaut

    GMC Member

  • New Member
  • 77 posts

Posted 13 June 2011 - 04:20 AM

Bump...
  • 0

#5 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16823 posts
  • Version:GM:Studio

Posted 13 June 2011 - 06:19 AM

Please don't bump your topics until the at least 48 hours have passed... see the Bumping Rules.

That said, what do you mean the y position doesn't change? how about a screen shot illustrating the problem? This would also be helpful for your second problem too... Which I suspect is caused by the sub_image of the sprite being reversed. So try using this code instead...


//CREATE EVENT
a_angle=0;
image_speed=0;
image_index=0;
sprite_index=whatever;

//STEP EVENT
if global.dir = 0 image_yscale=1 else image_yscale=-1;
a_angle = point_direction(x, y, mouse_x, mouse_y);

//DRAW EVENT
draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, image_yscale, a_angle, image_blend, image_alpha);


This code assumes that the ORIGINAL sprite is pointing right, has the y offset centered and the x offset at 0.
  • 0

#6 Joegernaut

Joegernaut

    GMC Member

  • New Member
  • 77 posts

Posted 13 June 2011 - 06:54 AM

Thanks for helping but I managed to fix this problem on my own. I've got another problem, can I pm you about it?

Joe
  • 0

#7 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16823 posts
  • Version:GM:Studio

Posted 13 June 2011 - 07:05 AM

Pm recieved, and replied to!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users