Jump to content


Member Since 12 Jan 2012
Offline Last Active Jan 12 2012 08:08 PM

Posts I've Made

In Topic: platformer combat problem, need help!

12 January 2012 - 08:09 PM

or am I going to have to get creative and fancy with coding to do that?


One simple idea is to have a variable that remembers the direction of the last direction button you pressed. I typically use image_xscale to flip sprites horizontally and use that for the directional, but you don't have to if you dont want to.

The idea is: when you move left, set this variable, let's call it dirvar, to -1. When you move right, set it to 1. Then create the punch/bullet/etc at relative x position dirvar*desired_distance, and set its hspeed to dirvar*desired_speed. If dirvar is equal to 1, the speed will be positive and the bullet will move to the right. If it's -1, the speed will be negative (but have the same magnitude) and the bullet will move to the left.

//Press shoot key
with(instance_create(x + dirvar*23,y,obj_bullet)){
  image_xscale = dirvar
  hspeed = dirvar*10

Thanks a lot! I was pretty sure there had to be a way to do it. :)