How Do You Keep Bullets In a straight Line?
hzapps
Member, PRO Posts: 173
I finally was able to get the moving enemy spawn a bullet and fly towards my actor, but it follows the actor instead of following a straight line until it destroys itself? Does anyone have any thoughts? How about how to keep the enemy actor from rotating away from my actor? I am using PlayerX, PlayerY already, but sometimes the enemy actor will continue rotating away from my actor eventhough it is moving towards it?
Comments
Tell us what behaviors or/attributes you have associated with those actors.
If you can upload screens of your settings or a vid of what is occurring, it would help out a big time. Otherwise I would check the cookbook, it should be just as easy as this:
you need in the bullet actor some attributes
bullettrigger - boolean - false
angle1 - real
angle2 - real
now do following
add a rule
bullettrigger false
add a change attribute behavior
insert in first field
self.angle1
insert in second field
atan((game.Playery-self.position.y)/(game.Playerx-self.position.x))+180
add another change attribute behavior
insert in first field
self.angle2
insert in second field
atan((game.Playery-self.position.y)/(game.Playerx-self.position.x))
the first one is if the player is on the left side of the bullet ... the other one if the player is on the right
now a new rule
if self.position.X > game.Player.X /// player is on the left
now insert a move behavior.
in the direction field insert
self.angle1
otherwise
insert a move behavior
in the direction field insert
self.angle2
i hope that works ... and i explained everything so it makes perfect sense for you
It rotates because, for some reason the player moves and its x and y coordinates changes, so it rotates relative to that to apply the new changes.