
It seems everthing tied together in the End Step, so I'm thinking I might have some commands in the create instance that are unnecessary, but apparently not causing any errors.Įdit: Here's the website that helped me along.
How to do mouse aiming in gamemaker 7 code#
I might post some code later if you guys could take a look if you see anything unnecessary or sloppy. To make the inventory look nicely I will take the following sizes: all the sprites of the items are 100x100. To draw the inventory a special object is used that is only placed in that room.
How to do mouse aiming in gamemaker 7 how to#
I've been back at trying to figure out the lengthdir scenario and I think I might finally have it whipped. In this tutorial I will explain how to do it in a special room for the inventory where everything is stored. Only because I thought this probably wasn't the most efficient way of coding it. I ended up trying this and it worked out pretty slick, but I didn't like that I would have to input the same WASD movement commands for each gun I choose to add to the game. Originally posted by TehGuy:One way to cheat this, IMO, is to make the sprite larger (make it player sprite size + gun sprite size), offset the gun in the sprite by however much you need, and set its center where the player would be and just rotate the sprite the same way you do with the player My_gun.y = y + y_offset + lengthdir_y(15, image_angle) My_gun.x = x + x_offset + lengthdir_x(6, image_angle) So I don't really know how to tie these commands together. The problem is that it does not stay positioned in the player hand properly. It rotates both clockwise and counter-clockwise with my player. My instance is only drawing one gun now, and it starts in the right location. Why do you say I only want to create one gun? Eventually I want to add other weapons so I wanted to hatch this out and I'll learn about the weapons arrays and what not later.Īnyhow, it seems that what I need to accomplish is all a matter of the End Step code. Everyone seems to create a cookie cutter player with the x,y of the weapon centered on the x,y of the player, and also use up,down,left,right movement rather than rotation like I am trying. I can appreciate that but there's not a lot of information out there, I've been searching high and low. Then moving the gun's direction, image_angle, and x,y coords should be easily handed in the step of the gun. You're creating multiple guns, you obviously don't want to do that, you only want to CREATE one gun. Originally posted by Negative Headed:I'll only give tips, I don't want to just give you the code, nothing is learned that way, so hopefully you're okay with that. Image_angle = point_direction(x,y,mouse_x,mouse_y) īullet = instance_create(x,y,obj_9mm_bullet) Some code for this in my obj_9mm_gun as follows: My_gun = instance_create(x + x_offset, y + y_offset, obj_9mm_gun) Some code for this in my obj_player as follows:Įdit: my player is named obj_hero (not to get confused with code below)

I'm not using a typical up/down/left/right movement set-up. Other than that, the gun follows my mouse and shoots correctly.Īnyone know how I can lock the gun to match the player rotation? My player can rotate in a circle but the gun stays in a fixed position. My problem is, when I rotate my player using the A or D keys, the gun doesn't rotate with the player. I used this code to create my gun in position on the left arm. I'm using a non-typical player sprite that looks like a U shape.
