problem about spawning a bullet to Player

btigerbtiger Member Posts: 8
edited November -1 in Working with GS (Mac)
Hi, I'm new to GS and trying to make an aircraft shooting game.
Could someone help me to solve this problem?
How to make an actor spawn a bullet move to another actor, and if the second actor move away, the bullet will still move to that direction and go beyond the screen boundary?

Thanks a lot:)

Comments

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    Make a rule on your aircraft, something like

    When actor receives touch
    spawn actor "Bullet".

    Then in your bullet actor add a move and destroy rule. Make the move rule in the direction you want at a speed you want. Add a destroy rule so after 1 second it is destroyed (plenty of time to leave the screen).

    Also add a rule that says:
    if actor Bullet overlaps or collides with actor Enemy
    destroy actor

    In your enemy actor have a similar rule:
    if actor Enemy overlaps or collides with actor Bullet
    destroy actor

    This will work in any situation where you want to shoot straight. If you want to shoot with angles, you'll need to capture the X,Y coordinates of the enemy and use that as a destination point for the bullet using some custom attributes.
  • btigerbtiger Member Posts: 8
    Thanks a lot, mulcahy and tshirtbooth, your tutorial helped me a lot.
    And I have a further question, if I want to have a bullet with static velocity and have no accelaration, how to do that?
    I tryed the "Move To" behavior and when the bullet get to the target X,Y, the bullet won't go further and stayed at that point.
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Hi btiger,
    You can try a Change Velocity behavior if you have a target location using game attributes, game.TargetX and game.TargetY. (you'll need to create those as real type game attributes)

    With the Change Velocity, you can set a static velocity, and set the direction relative to scene with the vectorToAngle function.

    vectorToAngle(game.TargetX-self.Position.X, game.TargetY-self.Position.Y)

    just use that format and select the correct attributes, and you should be good to go.
  • btigerbtiger Member Posts: 8
    Hi CodeMonkey

    Thanks a lot for your help, It's great and it works very well.
    The "Change Velocity" behavior and the "vectorToAngle" function are what I need. But I find that “Change Velocity" almost have same attributes as "Move" behavior, what's different between them? When I try to replace "Change Velocity" with "Move", the game would "Pause" at that behavior.
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Analogy time.
    Assuming you are on an ice rink.
    Change Velocity: You push a hockey puck with the stick. You change its velocity and it keeps on going until it hits something with no other interaction from you.

    Move: You are carrying the hockey stick to go get the puck and you are moving the stick. You can continuously control the direction the stick is going depending on where you are going.

    Though in the analogy you can throw your stick at the puck and that moves it, but it rarely gives you the controlled outcome you want. :)
  • btigerbtiger Member Posts: 8
    I got it, when I replaced the "Change Velocity" into "Move" behavior, the bullet became a tracking bullet(I got a tacking missile,haha and I don't know why it doesn't work last time).

    In my thought, the "Change Velocity" always can't change direction, it only followed the first gave direction and the "Move" can change direction during moving process that means more control. Am I right?
Sign In or Register to comment.