problem about spawning a bullet to Player
btiger
Member Posts: 8
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:)
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
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.
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left
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.
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.
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.
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.
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?