![]() ![]() (If it hasn't occurred to you yet, building games requires a well-developed understanding of all kinds of math, so best just to embrace it). You'll do this with a little trigonometry. You're feeding _bullet_x and _bullet_y into instance_create just like you should, but we need to calculate new values for _bullet_x and _bullet_y depending on what direction the player is facing. ![]() So this is the fun part (or the hard part, depending on your perspective ) Offset_angle = arcsin( y_offset / offset_distance ) // I believe this will return an angle in radians but you might look it up in the manual Offset_distance = sqrt( x_offset^2 + y_offset^2 ) If you're unsure how to get offset_distance and offset_angle, one way you could go about it is just counting the horizontal and vertical offsets in pixels in your sprite. The leading '_' characters are just a personal notation style. Good for helper variables in computations. _bullet.speed = 20 if you haven't seen 'var' before it just means a temporary variable that will be discarded when that piece of code is finished running. _bullet.direction = point_direction(_bullet_x,_bullet_y,mouse_x,mouse_y) Var _bullet = instance_create(_bullet_x,_bullet_y,obj_bullet) Var _bullet_y = y + offset_distance * sin( _player_direction + offset_angle) // use sin or dsin depending on whether your angle is in radians/degrees Var _bullet_x = x + offset_distance * cos( _player_direction + offset_angle) // use cos or dcos depending on whether your angle is in radians/degrees Var _player_direction = point_direction(x,y,mouse_x,mouse_y) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |