Page 1 of 1

### Move to position with speed limit

Posted: Sat, 14. Jun 08, 09:16
The actual speed varies with the object (size, acceleration - did not inquire) but it is possible to have an object fly to XYZ at a specific speed.

I tried this with a fighter drone and any entered speed between 30 and 370 is almost exactly on the mark.
Arguments
1: Speed.Limit , Var/Number , 'Speed Limit'

001 \$Target = get player tracking aim
003 \$Sector = [PLAYERSHIP] -> get sector
004
005 while \$Target -> exists
006 \$X = \$Target -> get x position
007 \$Y = \$Target -> get y position
008 \$Z = \$Target -> get z position
009 \$X = \$X + \$Speed.Limit * 4
010 @ START \$Target -> call script '!move.movetoposition' : sector=\$Sector position x=\$X position y=\$Y position z=\$Z precision=5
011 @ = wait 150 ms
012 end
Unlike attack run with speed limit this does not require a target object.

Posted: Sat, 14. Jun 08, 09:40
Interesting, what makes it "tick"?

Posted: Sat, 14. Jun 08, 11:44
You know that ships automatically slow down when approaching the move.to destination.

Like a carrot on a stick I keep this destination a short distance in front of the ship so it slowly follows my carrot.
The length of the stick defines the speed.

I'm making a ship "tow" something but the heavier the load, the slower the ship moves.
Cool effect and technically impossible with regular commands but... why limit myself to regular commands? =)

As a result I can liberally move the target with force position because the tow ship has the speed limit built in. Doing a useful speed simulation with force position is very ardous and inaccurate.

Posted: Sat, 14. Jun 08, 19:39
Good call Gaz, good call.

You have no idea of how much time I spent pondering trying to find an elegant (meaning not exceeding 100 lines of code mostly mathematical equations) for such a system.

Was writing an "Maintain Orbit script" but had to make sure the ship was a 0m/s and just simulate velocity with the forced move command.

Posted: Sat, 14. Jun 08, 20:32
rather interesting little snippet you have there.

Posted: Sat, 14. Jun 08, 20:41
The real thing is used for the MARS goblins when they bring things back to their master so you can see how it works. =)

Posted: Sat, 14. Jun 08, 21:13
Gazz wrote:Like a carrot on a stick I keep this destination a short distance in front of the ship so it slowly follows my carrot.
The length of the stick defines the speed.
Ok, I get that now, so the example in the OP shows "how to hold the carrot if you want to go East".

If you do want to go to a specified point, then naturally you have to add the "Are we there yet?" test, and use unit-lenght direction vector instead of (1,0,0). Floating point math?

Posted: Sun, 15. Jun 08, 04:33
Basically, yes.
This example was my first test for it and it's a lot easier to read than the real thing with proper vectors and checks.

Doesn't require floating point math, though. A few meters give or take won't matter since I do not use a 1 ms wait.
The higher the timing delay the higher the fluctuation in ship speed. 3-8 m/s in this example.
If you use this on the playership you might want to use a 1 ms wait but not for every ship.

If you want to see the complete script, look at the goblin.control and flyto scripts. Since a goblin runs 3 simultaneous tasks to tow something it's not for the faint of heart. =)

Posted: Mon, 16. Jun 08, 15:27
This would be great for an "attack in a pack" type of command

Posted: Tue, 17. Jun 08, 05:01
the main problem is that X is not always forward, u will need to compute the forward vector then increase the position down that vector at a set speed amount.

which basically what my warp drive does. Althou the step is much better making it move much faster.

there are a few other problems, the player can mess things up when they try to move the ship.

u'll have to adjust the direction vector to match the players current heading.

or, like my Advanced Thruster control script, fix the direction allowing the player to look in a different direction.

which reminds me, i should fix that, with the new commands added it should now be fully working with a small edit