First off, I am a newbie with the Galaxy editor, so any help is really appreciated.
I am trying to make units behave as follows. The unit moves in the angle it faces until it is blocked (pathing in that direction is not possible due to a wall, another unit, a doodad, etc.). When that happens, the unit should turn 180 degrees and repeat. This would cause the unit to patrol between walls/objects.
First I tried doing this with triggers, but there is no Event that says something like 'Unit Collides' or whatever. I can make a unit turn 180 degrees when it reaches a point or region, but that would require a LOT of regions. Still, this might be a possibility. However, I cannot figure out how to make a unit move forwards.
Does anyone know how to make a unit walk forwards or does anyone have a better idea than triggers to make unit turn around when something blocks them?
That's not the behaviour I am looking for. Patrol will let a unit find its own way between the two points. However, I want my unit to turn around when it collides with something it cannot pass through, but always keep walking in that exact straight line. Ideally this type of unit could be placed anywhere and do that exact thing.
I fear it might be hard to accomplish, though I have seen some people mention that a Behaviour might be able to pull something off, perhaps when combined with a Validator, but for now I will stick to what I understand. :)
Pretty much, yeah! If you could somehow calculate the angle of impact, you could make the unit into a real pinball, but that seems very hard, if not impossible. Though in my case, I would be happy if the unit would simply run back and forth in a straight line, only turning around when hitting something.
My preliminary spider sense guess work says this should be pretty doable with a trigger. The easiest should be against other units. Have an event proc every 0.2 second or so that causes the unit to move half a square in front of it.. Use a "closest unit" action and see if any unit is within the combined radius of the two units. If they are within each other's radius, then they impacted. You can then use some momentum physics to determine the effect of the impact with a new velocity (I'm talking about pinballs colliding here, so two round balls).
Collision with walls should also be doable. Each time your 0.2 second timer procs, look ahead half a square and use the "is point pathable" condition (or something similar). This trigger will let you know if you won't be able make your next half square journey forward, thus you'll need to adjust movement. I'm not positive how to find out which direction your unit will travel in after hitting the wall as I have no idea how you'd be able to tell which way you impacted the wall. (diagonally, horizontally/vertically).
Thanks for the answer! I think this is enough to get me on my way! Since I only need my unit to turn 180 degrees, I won't need to do anything fancy determining its movement direction. I suppost I will assign each unit a point that keeps moving in front of my unit then. I'll let you know how it turned out!
Just to let you all know I got it all to work. Every X time I check for each unit if the point in front of them (based on their facing angle) is passable. If it isn't, I turn the unit 180 degrees. Then I order the unit to move to the point in front of it.
I must warn you that this only works properly if the unit collides with a wall straight on and not under an angle. If it does collide with the wall under an angle, odds are the point in front of the unit does not hit the wall yet and your unit might turn.
However, for what I want to do it works like a charm. Thanks for the help, guys!
Alternatively, have an event that repeats every x time.
1) The trigger would check the distance between the point variable described below and the unit's current position. The actions have to be done in this order.
2) The trigger would save the current position of the unit to a point variable.
If the distance is below a certain threshold that you may decide, then the unit is blocked.
That's what I thought about at first too, Eiviyn, however, the problem with that method is that it doesn't command the unit to move every x seconds. Since it doesn't have small increments of movement, the game's pathing will make the unit travel around barriers, thus it's no longer walking in a straight line. While you could remove the unit's lateral movement, I don't know what that will do to the pathing (will it walk all the way to the wall or will it stop at the fork in the road trying to move to the side, but unable to do so?).
My initial idea, before I posted, was to tell it to move to the other end of the map with lateral movement disabled and then use a "Unit has Idled" (or whatever it's called) event for a trigger. The trigger would then manually tell which direction for the unit to face and tell it to move in the opposite direction. However, as I said, I dunno what that will do to the pathing of the unit, thus I didn't bring it up. My hope was that without lateral movement, the moment the unit hits a wall, it will start idling since it's unable to move to the sides, thus giving the appearance that the unit turned around almost instantly.
That's actually an interesting thing to try. I must say that my current triggers work perfectly btw, but it's still good to try alternatives that might be more elegant.
For reference, I set the unit's turn speed to 0, let them move to a point a small bit in front of them every 0.3 seconds unless that point is not passable, in which case they turn around.
It's easy enough to implement these kinds of behaviours, but to perfect them, especially with the default pathing, it takes some thinking.
The issue i'm having with this is that the units don't turn the full 90 degrees. They tend to turn slightly under.
I've tried flooring the angle which the unit is at with FixedToInt(UnitGetFacing(UnitGroupLoopCurrent())) and i've even got while loops in the turning to make sure that it keeps repeating the turning until it's accurate but it just doesn't work.
Am I going about this the wrong way by using the current angle of the unit? Should I just write the angle the unit should be heading to a units custom variable and pull it from the move forward trigger or would it still cause the same error?
If you want to see what's happening on the map see attachment.
Hey guys,
First off, I am a newbie with the Galaxy editor, so any help is really appreciated.
I am trying to make units behave as follows. The unit moves in the angle it faces until it is blocked (pathing in that direction is not possible due to a wall, another unit, a doodad, etc.). When that happens, the unit should turn 180 degrees and repeat. This would cause the unit to patrol between walls/objects.
First I tried doing this with triggers, but there is no Event that says something like 'Unit Collides' or whatever. I can make a unit turn 180 degrees when it reaches a point or region, but that would require a LOT of regions. Still, this might be a possibility. However, I cannot figure out how to make a unit move forwards.
Does anyone know how to make a unit walk forwards or does anyone have a better idea than triggers to make unit turn around when something blocks them?
Cheers, Dysprosium
@DysprosiumDy: Go
Why don't you just order it to patrol.
@Vexal: Go
That's not the behaviour I am looking for. Patrol will let a unit find its own way between the two points. However, I want my unit to turn around when it collides with something it cannot pass through, but always keep walking in that exact straight line. Ideally this type of unit could be placed anywhere and do that exact thing.
I fear it might be hard to accomplish, though I have seen some people mention that a Behaviour might be able to pull something off, perhaps when combined with a Validator, but for now I will stick to what I understand. :)
@DysprosiumDy: Go
Like a pinball?
@Vexal: Go
Pretty much, yeah! If you could somehow calculate the angle of impact, you could make the unit into a real pinball, but that seems very hard, if not impossible. Though in my case, I would be happy if the unit would simply run back and forth in a straight line, only turning around when hitting something.
@Vexal: Go
I think he's going for more of a lemming.
@SquarelyCircle: Go
Yeah, a lemming best describes what I mean! Thanks!
My preliminary spider sense guess work says this should be pretty doable with a trigger. The easiest should be against other units. Have an event proc every 0.2 second or so that causes the unit to move half a square in front of it.. Use a "closest unit" action and see if any unit is within the combined radius of the two units. If they are within each other's radius, then they impacted. You can then use some momentum physics to determine the effect of the impact with a new velocity (I'm talking about pinballs colliding here, so two round balls).
Collision with walls should also be doable. Each time your 0.2 second timer procs, look ahead half a square and use the "is point pathable" condition (or something similar). This trigger will let you know if you won't be able make your next half square journey forward, thus you'll need to adjust movement. I'm not positive how to find out which direction your unit will travel in after hitting the wall as I have no idea how you'd be able to tell which way you impacted the wall. (diagonally, horizontally/vertically).
@Azkit: Go
Thanks for the answer! I think this is enough to get me on my way! Since I only need my unit to turn 180 degrees, I won't need to do anything fancy determining its movement direction. I suppost I will assign each unit a point that keeps moving in front of my unit then. I'll let you know how it turned out!
Just to let you all know I got it all to work. Every X time I check for each unit if the point in front of them (based on their facing angle) is passable. If it isn't, I turn the unit 180 degrees. Then I order the unit to move to the point in front of it.
I must warn you that this only works properly if the unit collides with a wall straight on and not under an angle. If it does collide with the wall under an angle, odds are the point in front of the unit does not hit the wall yet and your unit might turn.
However, for what I want to do it works like a charm. Thanks for the help, guys!
@DysprosiumDy: Go
This thread makes me want to make a pool simulation game. :p
Alternatively, have an event that repeats every x time.
1) The trigger would check the distance between the point variable described below and the unit's current position. The actions have to be done in this order.
2) The trigger would save the current position of the unit to a point variable.
If the distance is below a certain threshold that you may decide, then the unit is blocked.
@Eiviyn: Go
That's what I thought about at first too, Eiviyn, however, the problem with that method is that it doesn't command the unit to move every x seconds. Since it doesn't have small increments of movement, the game's pathing will make the unit travel around barriers, thus it's no longer walking in a straight line. While you could remove the unit's lateral movement, I don't know what that will do to the pathing (will it walk all the way to the wall or will it stop at the fork in the road trying to move to the side, but unable to do so?).
My initial idea, before I posted, was to tell it to move to the other end of the map with lateral movement disabled and then use a "Unit has Idled" (or whatever it's called) event for a trigger. The trigger would then manually tell which direction for the unit to face and tell it to move in the opposite direction. However, as I said, I dunno what that will do to the pathing of the unit, thus I didn't bring it up. My hope was that without lateral movement, the moment the unit hits a wall, it will start idling since it's unable to move to the sides, thus giving the appearance that the unit turned around almost instantly.
@Azkit: Go
That's actually an interesting thing to try. I must say that my current triggers work perfectly btw, but it's still good to try alternatives that might be more elegant.
For reference, I set the unit's turn speed to 0, let them move to a point a small bit in front of them every 0.3 seconds unless that point is not passable, in which case they turn around.
It's easy enough to implement these kinds of behaviours, but to perfect them, especially with the default pathing, it takes some thinking.
Any chance of showing how this was done... I'm trying to do something similar and i'm interested in how you've done it.
The issue i'm having with this is that the units don't turn the full 90 degrees. They tend to turn slightly under.
I've tried flooring the angle which the unit is at with FixedToInt(UnitGetFacing(UnitGroupLoopCurrent())) and i've even got while loops in the turning to make sure that it keeps repeating the turning until it's accurate but it just doesn't work.
Am I going about this the wrong way by using the current angle of the unit? Should I just write the angle the unit should be heading to a units custom variable and pull it from the move forward trigger or would it still cause the same error?
If you want to see what's happening on the map see attachment.
To spawn more units just press space ingame
bump again since 4 days and no response
bollocks to you all