Top-Down Shooter.. bullets help -SOLVED-
Sanction
Member Posts: 9
Hey guys I'm Matt.. I'm new to GameSalad!! Love it..
I need to some help getting my bullets to project in the direction of my mouse.. & then I need them disappear.
It seems to work but I also have the screen following the Player so it messes up when then screen moves and the spell stops at that location and not getting destroyed.. can anyone help me out or move me on the right direction?
this is what i got.. if you can read it
Actors: Player, Bullet
Game Attributes:
Attack_Type: 0 int
Mouse_X: 0 real
Mouse_Y: 0 real
Player:
---------------
On Key "space" is DOWN
DO:
change attribute,
Set: "game.Mouse_X" To: "game.mouse.pos"
change attribute,
Set: "game.Mouse_Y" To: "game.mouse.pos"
if "game.Attack_Type" = "0" {
DO:
Spawn Actor: "fireball" Place: "in back of actor"
In Direction: "0" Relative to: "actor"
from Pos: "0", "0" Relative to: "actor"
}
---------------
Bullet:
---------------
change attrivute,
Set: "self.MouseX" To: "game.Mouse_X"
change attrivute,
Set: "self.MouseY" To: "game.Mouse_Y"
move to,
move To: "self.MouseX", "self.MouseY" Relative to: "actor"
at a speed of: "300" []run to completion
_________________
I need to some help getting my bullets to project in the direction of my mouse.. & then I need them disappear.
It seems to work but I also have the screen following the Player so it messes up when then screen moves and the spell stops at that location and not getting destroyed.. can anyone help me out or move me on the right direction?
this is what i got.. if you can read it
Actors: Player, Bullet
Game Attributes:
Attack_Type: 0 int
Mouse_X: 0 real
Mouse_Y: 0 real
Player:
---------------
On Key "space" is DOWN
DO:
change attribute,
Set: "game.Mouse_X" To: "game.mouse.pos"
change attribute,
Set: "game.Mouse_Y" To: "game.mouse.pos"
if "game.Attack_Type" = "0" {
DO:
Spawn Actor: "fireball" Place: "in back of actor"
In Direction: "0" Relative to: "actor"
from Pos: "0", "0" Relative to: "actor"
}
---------------
Bullet:
---------------
change attrivute,
Set: "self.MouseX" To: "game.Mouse_X"
change attrivute,
Set: "self.MouseY" To: "game.Mouse_Y"
move to,
move To: "self.MouseX", "self.MouseY" Relative to: "actor"
at a speed of: "300" []run to completion
_________________
Comments
I just need to figure out how to destroy the bullets.. or would it be better to recycle them?
Pros and Cons of Destroying Bullets or Recycle Bullets anyone?
Spawning should not cause problems unless you go overboard with it.
You will need to record the angle between the bullet and the mouse position using a variable, lets call it mouseAngle.
When mouse is down change attribute mouseAngle to
vectorToAngle( game.Mouse.Position.X - self.Position.X , game.Mouse.Position.Y - self.Position.Y )
This will move the bullet precisely at the mouse position.
You can add another behaviour on whichever actor is spawning the bullet to spawn it only when mouse position is down.
So when the bullet is spawned it will get the angle in which it needs to move.
Hope that helps.
FIXED - multiple bullets going towards the mouse angle..
(added bullet its own attribute "MouseAngle")
FIXED - when I leave the screen initial area it messed all up..
(added CamX and CamY to vectorToangle formula!)
vectorToangle(CamX + game.mouse.x - self.position.x, CamY + game.mouse.y - self.position.y)