Keeping a unit within view.

Corleone

New Member
Reaction score
44
I'm currently working on a side-scroller map ( camera moves north all the time ) and I want my unit to stay within view. I made a region ( called Playable Area <gen> ) covering most of the panning camera's view and I make it move north all the time. Also made a arrow-key-movement system that makes sure you stay within the borders of the region. However, when my unit leaves the camera view at the bottom of the screen it doesn't keep it within the region borders, so I tried using
Code:
Keep in view
    Events
        Game - MyUnitY becomes Less than or equal to (Min Y of Playable Area <gen>)
    Conditions
    Actions
        Unit - Move MyUnit 0000 <gen> instantly to (MyUnitPosition offset by 100.00 towards (Facing of MyUnit 0000 <gen>) degrees), facing 90.00 degrees
        Set MyUnitPosition = (Position of MyUnit 0000 <gen>)
        Set MyUnitY = (Y of MyUnitPosition)

For some reason, it doesn't do anything though. Anyone got an idea what else I should try?
 

Corleone

New Member
Reaction score
44
Code:
        Game - MyUnitY becomes Less than or equal to (Min Y of Playable Area <gen>)

is maybe wrong? Try to debug your code.


Well, I tried lots of things for that, but I just can't seem to figure out what value would be right. If I could compare "MyUnitY" to another 'preset' real then that should work. However, thats not possible with this event. "MyUnitY" is being set every 0.20 seconds using another event, by the way, so that it's always 'up-to-date'. I dont know whether the (Min Y of Playable Area <gen>) is being updated or that it just sticks with the original value.
 

Chocobo

White-Flower
Reaction score
409
Well, I tried lots of things for that, but I just can't seem to figure out what value would be right. If I could compare "MyUnitY" to another 'preset' real then that should work. However, thats not possible with this event. "MyUnitY" is being set every 0.20 seconds using another event, by the way, so that it's always 'up-to-date'. I dont know whether the (Min Y of Playable Area <gen>) is being updated or that it just sticks with the original value.

MyUnitY = Pre-defined value. Can not be changed.
(Min Y of Playable Area <gen>) = Pre-defined value. Can't be changed.

You should use a periodic event.
 

Corleone

New Member
Reaction score
44
Strange.. I tried using similar periodic events to do this, but this time it works properly, for some reason.

Code:
Periodic Keep in view
    Events
        Time - Every 0.40 seconds of game time
    Conditions
        (Number of units in (Units in Playable Area <gen> owned by Player 1 (Red))) Equal to 0
    Actions
        Unit - Move MyUnit 0000 <gen> instantly to (MyUnitPosition offset by 150.00 towards 90.00 degrees)
        Set MyUnitPosition = (Position of MyUnit 0000 <gen>)

This very same trigger used to make my unit move north all the time, instead of only when its outside the region.

Thanks for the help, Chocobo.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top