need help with side scroller shooter game I'm making
MisterFisker
Member Posts: 1
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
Thanks!
-MisterFisker
Comments
The Canon example, included with GameSalad, seems like a good place to start.
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.
VectorToAngle(turretX-MouseX,turretY-MouseY)
That should also give you the bullet spawn angle...
VectorToAngle(turretX-MouseX,turretY-MouseY)
That should also give you the bullet spawn angle...
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)
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...
You may need to make the enemies move past instead of the scene scrolling. :-/
Cheers,
-W. V.
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.
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.