Home   Help Search Login Register  

Author Topic: Moving backwards  (Read 1365 times)

0 Members and 1 Guest are viewing this topic.

Sorcerer

  • Guest
Moving backwards
« on: 05 Oct 2006, 20:27:40 »
Is it possible to make a unit, like a tank, go from one waypint to another in reverse?

One of the real-life tank tactics is to move from one point of the line to another by pulling back and going forward in a V shape.
Making something like this look good, the tank needs to do the first part of the V backwards.

Can it be done?  :dunno:

Offline JasonO

  • OFPEC Patron
  • ****
  • Oh no...
    • The New Life RPG
Re: Moving backwards
« Reply #1 on: 05 Oct 2006, 22:05:12 »
Only way I can see this possible is by making the tank go in a straight line using the 'SetVelocity' command.

It can force the tank to move in 1 given direction.

AI cant drive backwards in the game. Thats OFP i'm afraid  :confused:

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: Moving backwards
« Reply #2 on: 06 Oct 2006, 00:12:03 »
Quote
AI cant drive backwards in the game...

oh but they can, but only when you want them to drive forwards....

Offline DEADRABBIT

  • Members
  • *
Re: Moving backwards
« Reply #3 on: 06 Oct 2006, 01:11:00 »
I think the AI drives backwards, when the position they have to move towards is very nearby. If you want to move a tank for example to a position behind him, and the position is like 500 meters away, the tank won't drive in reverse the 500 meters to the position. Instead, it turns and then moves forward, like anyone would do. But if the position is only one meter away instead of 500, it's no use to turn around first and then drive one silly meter.

A script for this could look like this:

Code: [Select]
;; Script to drive a vehicle in reverse over a certain distance in a straight line
;; Use only with driving over straight areas, hills may cause the vehicle to deviate from its path
;; [Car,300] exec "thisscript.sqs"

_veh = _this select 0
_s = _this select 1

_dir = getDir _veh
_pos = getPos _veh

;; A distance delta s
_d_s = 0.1

;; Find the ratio between x-axis and y-axis negative movement
_d_x = _d_s * -1 * (sin _dir)
_d_y = _d_s * -1 * (cos _dir)

;; Scalars
_m = 1
_d_m = 1

;; Distance already passed
_s_covered = 0

;; Old positions
_x_old = _pos select 0
_y_old = _pos select 1

#loop

@(unitReady _veh)

;; If the distance covered exceeds or is equal to the distance to be covered, stop the vehicle and exit
? _s_covered >= _s : _veh doMove getPos _veh; exit

;; Set a new position for the vehicle to move to
_x_new = _x_old + (_m * _d_x)
_y_new = _y_old + (_m * _d_y)

;; Put those new position coordinates in an array
_pos_new = [_x_new,_y_new,0]

;; Make the vehicle move to the new position
_veh doMove _pos_new

~0.1

@(speed _veh > 0 Or unitReady _veh Or not canMove _veh)

;; If the vehicle broke down, exit
? not canMove _veh : exit

;; If the vehicle actually moved over such a small distance, then leave the scalar _m at it's current value and continue the process till the end
? speed _veh > 0 : _x_old = _x_new; _y_old = _y_new; _s_covered = _s_covered + sqrt ((_x_old)^2 + (_y_old)^2); goto "loop"

;; If the vehicle didn't move at all, because it considered the distance to be not important, increase the _m scalar with a _d_m scalar and then
;; repeat the move
? unitReady _veh : _m = _m + _d_m; goto "loop"

I don't know if this code will work. If it's bugless, as in, it is run properly without errors, the result should be positive.

Edit: found a small error in my script. Corrected it.
« Last Edit: 06 Oct 2006, 12:00:03 by DEADRABBIT »

Sorcerer

  • Guest
Re: Moving backwards
« Reply #4 on: 06 Oct 2006, 01:42:59 »
Thanks, I'll try it out right now!!

Not too strong with scripting myself, so it's good to see others have it covered!!  :good:

Sorcerer

  • Guest
Re: Moving backwards
« Reply #5 on: 06 Oct 2006, 02:07:54 »
DEADRABBIT! There seems to be something about the scribt you sent it doesn't like!
When I run it in the game it says something like "(unitready _veh) type string: expected array or object".

Can you take another look at it?  :)

Offline DEADRABBIT

  • Members
  • *
Re: Moving backwards
« Reply #6 on: 06 Oct 2006, 11:17:15 »
DEADRABBIT! There seems to be something about the scribt you sent it doesn't like!
When I run it in the game it says something like "(unitready _veh) type string: expected array or object".

Can you take another look at it?  :)



Already found the error. I used a string for an object in the exec command.

Should work now. I hope....