DroneAITick

Started by Xalos, February 28, 2015, 09:52:42 AM

Previous topic - Next topic

Xalos

I've been trying to write a continuous-physics drone AI function which would move a drone at a fixed speed every frame towards a goal, but I'm having some problems getting the drone to enter a straight line of motion once it's turned towards the point it's supposed to be travelling to.  Currently, it will turn towards the goal as expected, but I can't figure out how to make it leave the turning circle on the line which intersects the goal and is tangent to the circle.  As a result, it will just jitter between turning left and turning right, and I've had to hack in a distance check to actually get it to land at the goal.

Inputs: UnitID ImageSlot GoalX GoalY Speed TurnSpeed
   UnitID = the drone's base
   ImageSlot = the image slot for the drone
   GoalX = the X position of the tile to fly to
   GoalY = the Y position of the tile to fly to
   Speed = the drone's speed, in tiles per second
   TurnSpeed = the drone's turning speed, in radians per second
   TurnDir = which way the drone will turn if heading directly away from its goal, 0 being clockwise
Outputs: ReachedGoal
   ReachedGoal = has the drone reached its goal?


Can anyone help me figure out a way to get it to actually leave the turning circle when it's supposed to, instead of continuing slightly past where it should?

pawel345

Im on my phone rigth now so i cant compleatly analyse your code but you can take the rotation function from the guns in alpha sector. Also dig this subformu for a bit there is a topic by eduroam i think about mking flying drones. Aditonaly Grazzur i think has programed a cw1 like drone so you can chck out that code.

Xalos

The drones already rotate towards their target, it's getting them to break free of the turning circle that's the problem.

Grayzzur's drones seem to turn and move seperately, which effectively means they're tracing a polygon with a high number of sides - which isn't exactly what I want.  They also seem to have code to stop once they've reached the target, as opposed to continuing past the target and sending a pulse to signal that the drone has reached/passed the target on this tick.


I can't actually find eduran's flying drone code anywhere, just the map for it.  I don't know how to extract scripts from maps or even if it's possible or allowed, but I have a sneaking suspicion that his code probably similarly turns and moves the drones seperately, since that's easier to do and isn't clearly different at first glance.

kwinse

#3
Quote from: Xalos on February 28, 2015, 10:32:39 AM
I can't actually find eduran's flying drone code anywhere, just the map for it.  I don't know how to extract scripts from maps or even if it's possible or allowed, but I have a sneaking suspicion that his code probably similarly turns and moves the drones seperately, since that's easier to do and isn't clearly different at first glance.

http://knucklecracker.com/forums/index.php?topic=15387.0

And afaik, grabbing scripts from published maps is generally okay as long as you give credit.

pawel345

You can extract codes form the maps by copying the map to your projects folder and then open it in the editor. And it's allowed, even opening the campaign maps and so on. There is a topic about that somewhere so you can read it if you need better instructions. In the gun script the gun rotates then shoots that's why I through that if you just change the shoot algorithm with QueueMove command it might work. Good luck

Xalos

Thanks guys - useful stuff to know!