bullets
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
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
Hope it helped you (:
cheers
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.
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
cheers
Thanks
@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