bullets

deej011deej011 Member Posts: 159
edited December 2011 in Working with GS (Mac)
hi,
i was just wanting to know how do i make a bullet spawn from one actor and move towards the position another actor is at the time the bullet was fired?

cheers

Comments

  • deej011deej011 Member Posts: 159
    anyone?
  • flapairflapair Member Posts: 67
    I found a video that can help you:
    Hope it helped you (:
  • deej011deej011 Member Posts: 159
    thanks for the help but i was wondering how to make the bullet go towards another actor?

    cheers
  • muoch10muoch10 Member Posts: 112
    edited December 2011
    Make 3 actors, the bullet, the player spawning the bullet, and the enemy. create 2 real game attributes, one called enemy x and enemy y, have the enemy change enemy x and enemy y to there position, so enemy postion x = enemy x, same thing with y (use change attribute if u didnt know). Then in the bullet use move to behavior and then set the x and y cordinates to enemy x and enemy y. Then on the player set the conditions for spawning the bullet, like pressing space, and then say spawn bullet. That should work.

    p.s if u want the bullet to kill the enemy just say on the bullet when collide or overlaps with enemy destroy and on the enemy say when overlaps or collides with bullet destroy.
  • deej011deej011 Member Posts: 159
    when i use change attribute the goes to where the enemy was and won't chance the x and y position of the next bullets?
  • guerinedguerined Member Posts: 11
    Hello deej011,

    First, I wish you a happy new year.
    Regarding your question,
    Make 3 actors: ennemy, bullet and gun. Create 2 real GAME attributes, one called ennemyX and ennemyY. Edit the ennemy actor and add 2 constrain attribute behaviors:
    - constrain attribute game.ennemyX to self.position.X
    - constrain attribute game.ennemyY to self.position.Y
    Constrain attribute will make sure that it is real time updated with the position of the ennemy.
    Then in the bullet, create 2 ACTOR attributes: TargetX and TargetY. Edit the bullet actor and add 2 change attribute behaviors:
    - change attribute self.TargetX to game.ennemyX
    - change attribute self.TargetY to game.ennemyY
    Change attibute will do it only once. Then you will have the coordinate of the ennemy stored in those attribute at the time the bullet has been spawned. Each bullet will contain the coordinates of its target.
    Add a timer with 0.1 second and then drag into the timer a MoveTo behavior and move to TargetX and TargetY. The timer will ensure that the above change attribute will have been processed before processing the MoveTo

    I have made a quick file in GameSalad, let me know if you want it by email.

    Regards
    David
  • deej011deej011 Member Posts: 159
    if thanks for the hep i could like the gs file thank you send it to deej_011@hotmail.com
  • guerinedguerined Member Posts: 11
    done!
  • deej011deej011 Member Posts: 159
    awesome works great just one other thing how do u make either the bullet keep moving or be distroyed if the bullet misses the enemy?

    cheers
  • jckmcgrawjckmcgraw Member Posts: 647
    @guerined I have been trying to do the same thing... Could I have the file? My email is jckmcgraw@gmail.com

    Thanks
  • guerinedguerined Member Posts: 11
    @jckmcgraw: I just emailed you the file

    @deej011: I would suggest a timer to destroy the bullet when it is no longer moving (you can test linear velocity X and Y =0). To make it even more efficient, I would recommend to combine all this with the recycling method from Tshirtboot. This way you would maximize the performance.

    Regards
    David
  • deej011deej011 Member Posts: 159
    thanks that worked fine for what i need
  • jckmcgrawjckmcgraw Member Posts: 647
    @guerined Thanks
Sign In or Register to comment.