Question about constrain.
I really don't have an issue, just wondering if someone could give me some insight on how a process works. Let me give you a scenario.
A tower defense game. I have a turret that Rotates to Angle using Vector to Angle. It rotates to game.EnemyX and game.EnemY and works fine.
Enemy1 enters the zone and constrains self.X to game.EnemyX and self.Y to game.EnemyY. Turret rotates to enemy1and tracks without issue.
Enemy 2 enters the zone and constrains self.X to game.EnemyX and self.Y to game.EnemyY. The turret still tracks Enemy1 until dead or out of the zone. Once enemy1 is dead or gone, it targets enemy2.
I am glad that it works, but wanting to know why this does not cause a conflict since enemy2 is also constraining its self.X to game.EnemyX and self.Y to game.EnemyY at the same time enemy1 is.
I used constrain and global variables to do this. I tried timers with tables and it would glitch out and the turret would at times bounce back and forth rapidly.
Any information would be helpful!
Thanks!
Comments
Are you constraining self.Position.X to game.enemyX or are you constraining game.enemyX to self.Position.X?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Sorry. Had that backwards. The enemy constrains game.enemX to self.PositionX. The turret then uses game.enemyX to follow him.
How did you set up the rule/behavior for the turret actor to track the enemy?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Turret rule
Rotate to Angle
vectorToAngle( game.Enemy_X - self.Position.X , game.Enemy_Y - self.Position.Y )
This is the only rule for the turret.
Enemy Rule
When overlaps or collides with actor of type Zone1
Constrain Attribute game.Enemy_X to self.PositionX
Constrain Attribute game.Enemy_Y to self.PositionY
Zone1 is just a round actor that is there to let the turret know the enemy is in range.
Maybe this this thread would help:
http://forums.gamesalad.com/discussion/comment/415325/#Comment_415325
Sorry if I am confusing things. I don't have an issue getting it to work. I am just wondering why there is not a conflict when another enemy with the same rules comes into the zone trying to constrain game.EnemyX to self.PositionX.
I just assumed there would be an issue.
Oh ...OK
So you wonder why its only registering the first enemy in the zone and not the second?
Perhaps its because rules set it to constrain enemy2 and then immediately after that its constraining enemy1. Since enemy1 was the last to be constrained, its going to retain that one.
As an experiment, try moving enemy1 so that its lower in the scene layers. (Below enemy2.) Then see if you get the opposite effect.
I am still trying to understand the order it decides to follow. If I have 1 actor replicated 4 times one after the other with the same rule to constrain game.EnemyX to self.PositionX, how does the game engine know to go in order.