need help with side scroller shooter game I'm making

MisterFiskerMisterFisker Member Posts: 1
edited November -1 in Working with GS (Mac)
I am currently making a side scroller shooter game where you can move the character with wasd, and I want to make where you're able to aim with the mouse and shoot with the clicker and the bullet actor will go to where the mouse was clicked. To do this I want to somehow make the character's gun follow the mouse and then once I click, the bullets should go in the direction of the mouse. My guess is I'd have to make the upper part and the lower part of the character two different actors, and have the animation for the running on the lower and an animation for the aiming and shooting on the upper. It would be very helpful to get your take on this.
Thanks!
-MisterFisker

Comments

  • PhoticsPhotics Member Posts: 4,172
    Heh... figuring out this type of shooting is the next part of my project. Yesterday I added Fire (Thrust), today I'll add guns (well, one main canon) and tomorrow (if I'm on schedule) I'll add explosions.

    The Canon example, included with GameSalad, seems like a good place to start.
  • PhoticsPhotics Member Posts: 4,172
    Heh... now that I finally have my turret welded to my ship, I'm working on making it fire. The first part is rotation, but I can't seem to get it right.

    From what I'm reading on the forums, scrolling might be an issue.

    The Canon example has this...
    max( game.Mouse.Position.X , self.Position.X )
    max( game.Mouse.Position.Y , self.Position.Y )

    ...but I don't think that's going to work. When I tried messing around with that, my canon would either rotate a little bit then stop, or not rotate at all. I'm thinking that I might need to come up with some better math.

    I think Rotate to Angle might be better, as my canon rotates 360 degrees, but I'll have to figure out how to calculate that. It's been a while since I've been in High School Math class.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    The first thing I would try is rotate to Angle like you said. To get the Angle, I would use:

    VectorToAngle(turretX-MouseX,turretY-MouseY)

    That should also give you the bullet spawn angle...
  • firemaplegamesfiremaplegames Member Posts: 3,211
    The first thing I would try is rotate to Angle like you said. To get the Angle, I would use:

    VectorToAngle(turretX-MouseX,turretY-MouseY)

    That should also give you the bullet spawn angle...
  • PhoticsPhotics Member Posts: 4,172
    OK, here's what I learned.

    1) When making graphics... If you're going to make a turret, make the shooting part aim towards the right. I had my turret aiming upwards. That can be confusing when trying to figure out angles.

    2) Make it movable. It wouldn't rotate until I checked that box. (Heh... I was wondering why my formulas were ineffective until I changed that setting.)

    This is the closest I got...
    vectorToAngle( game.Mouse.Position.X - self.Position.X , game.Mouse.Position.Y - self.Position.Y )

    It doesn't work properly, unless I put the Fighter/turret at the bottom left of the playfield... as close to origin as my boundaries allow. It works well from that corner. It seems that once the camera has to move, it gets confused. I tried both relative to Actor and Scene... and it seems that scene works better.

    I'm using constrain to keep the turret on top of the ship.
    The game level is 2048x2048
    The turret is 32x32(Image 64x64) and the ship is 64x64(image 128x128)
  • firemaplegamesfiremaplegames Member Posts: 3,211
    I haven't tried it yet, but you might also need to account for the camera offset.

    INSTANCES in the scene have access to the camera.originX and camera.originY ( the lower left hand corner of the visible area)

    Only instances, NOT the prototype, have access to the camera data. So you will have to double-click the instance, and click the padlock to access the instance behaviors. You could also just have a separate "camera watcher" actor that always keeps track of the camera offset and stores them in global game variables. That's how I do it in Stunt Squirrels.

    So in your vector to angle calculation, account for that offset as well, like this:

    vectorToAngle(game.Mouse.Position.X - (self.Position.X-game.Camera.OriginX) , game.Mouse.Position.Y - (self.Position.Y-game.Camera.OriginY) )

    Like I said, I haven't tried it yet, but it might be a good place to start...
  • TheBigWo0pTheBigWo0p Member Posts: 22
    I was talking to tshirtbooth in another forum about this and it looks like scrolling is not going to work. I spent all night last night trying countless things on a topdown shooter but never got rotation to follow the mouse accurately.

    You may need to make the enemies move past instead of the scene scrolling. :-/

    Cheers,
    -W. V.
  • PhoticsPhotics Member Posts: 4,172
    I'm in the process of figuring this out. I had to create a crude, but effective, debugger to see what was going on. I fairly confident that it's a camera issue. The function used in my previous post was comparing apples to oranges. The mouse position is relative to the screen while the ship position is relative to the game area.
  • PhoticsPhotics Member Posts: 4,172
    This is starting to feel like Robocop, the turret tracking is getting better. I remember the scene where you see from Robocop's perspective and someone is moving a pen around for Robocop to track. (Heh... it's been a while since I seen the movie, so my memory might be fuzzy... but I think it was something like that.)

    In other words, I'm getting closer. Here's the formula so far...
    vectorToAngle(( game.Mouse.Position.X + scene.Camera.Origin.X )- self.Position.X ,( game.Mouse.Position.Y + scene.Camera.Origin.Y )- self.Position.Y )

    The problem is that it doesn't work past 180 degrees. I'll have to figure that out. I think I can fix it.
  • PhoticsPhotics Member Posts: 4,172
    Muwhahaha... my gun turret tracks the mouse like the eye of Sauron now.

    My makeshift debug helped me to see what was going on. When the degree was greater than 180, it went negative. To fix this, I simply told it to add 360 when the value wasn't greater than or equal to zero.
  • rebumprebump Member Posts: 1,058
    Yeah, there is some crazy values in rotation angles. I've seen "debug" display text show it to have values greater than 360/-360, I've seen it never be negative, I've seen it never be more than 359 (i.e. it uses a modulus 360 on the value), etc. Some of what I experience may have been over the last few versions of GS (i.e 0.7.0 to 0.8.3). However, the implementation should have remained the same and if not you think they would have mentioned it. Its a lot of trial and error sometimes.
Sign In or Register to comment.