How to make an enemy move like in time4cat
Hello, I'm trying to create enemies that will only move when the mouse moves, just like in the game time4cat. Let's say I have an enemy that only goes in one direction (up screen to down screen). I want it to move down only when i move the mouse (in any direction) and I want it to move to the same speed that I'm moving the mouse. How can I do that? How can I create attributes that relate to the movement of the mouse or rules like : if mouse moves change boolean attribute to true?
Thank you,
Thank you,
Best Answer
-
MobileRocketGames Posts: 128
That's pretty easy. First create 4 real game attributes. Call them StartPosX and EndPosX and StartPosY and EndPosY. Then create one integer attribute and call it "EnemyMovement".
Next place the following code in an actor (any actor, just create a box off screen and throw it in there).
Constrain attribute StartPosX to Game.Mouse.Position.X
Constrain attribute StartPosY to Game.Mouse.Position.Y
Then you are going to create a timer system that fires every .25 seconds.
Since you are new you can use a timer behaviour set to "every".
Inside that timer put two change attribute behaviours
change attribute EndPosX to StartPosX
change attribute EndPosY to StartPosY
Next create a rule:- Rule (type = any, not all, this is crucial)
- attribute StartPosX ≠ EndPosX:
- attribute StartPosX ≠ EndPosX:
- change attribute game.EnemyMovement to 1
after .1 seconds:- change attribute game.EnemyMovement to 0
Thats it!
For all your enemies, their movement behaviours should be encased in a rule that says if game.EnemyMovement = 1 then do your movement behaviours. This means they will only move when the EnemyMovement attribute is 1, which it will only be when the mouse is moving, and will turn back to zero 100-350 milliseconds after your mouse stops moving. This extra time is to give the system a buffer so it doesnt hiccup flagging the movement attribute, if there was no .1 second timer it would stutter. If you want even less time between when the enemies stop moving and when the mouse stops moving then reduce the .25 second timer.
Later on you should learn to create your own timers, but for now this should accomplish what you want. I took the liberty (i dont know why) of creating this system and testing it out. Works great.
http://www32.zippyshare.com/v/665897/file.html
Answers
Rule (type = any, not all, this is crucial)
attribute StartPosX ≠ EndPosX:
attribute StartPosX ≠ EndPosX:
The last line should be StartPosY≠ EndPosY:
Learning a bit more everyday! ^:)^
I just uhh, added that in to see if you were paying attention B-)