Home   Help Search Login Register  

Author Topic: Help with a movement script  (Read 1302 times)

0 Members and 1 Guest are viewing this topic.

Offline romma

  • Members
  • *
Help with a movement script
« on: 04 Feb 2009, 10:06:24 »
Hi Guys

Could anyone help me out with writing these two script:

1. A script to seemlessly change the direction a unit is facing towards when given a direction. The setDir command sort of jumps the unit towards a given direction instead of a continuous movement.

2. A script to move a unit forward in the direction it is facing at a speed specified. The unit will only stop moving when a speed of 0 is specified. The unit should also only move in a straight line.

Any help with these two scripts will be greatly appreciated.


Offline Ext3rmin4tor

  • Members
  • *
Re: Help with a movement script
« Reply #1 on: 04 Feb 2009, 12:36:52 »
Answer to question 1:

Code: [Select]
_unit = _this select 0
_b = _this select 1
_a = getDir _unit
_x = getPos _unit select 0
_y = getPos _unit select 1
_z = getPos _unit select 2
_k = 20
_newX = _x + (_k * sin(_a + _b))
_newY = _y + (_k * cos(_a + _b))
_newZ = _z
_unit doWatch[_newX, _newY, _newZ]
exit

Remember that if the unit is a tank this will make the turret to turn and face the given direction, not the tank itself.

Call the script using [unit, direction] exec "dir.sqs"

Remember that the angles in ArmA are azimut and not radians, so the 0 is on the top and they increase clockwise.
« Last Edit: 04 Feb 2009, 12:40:20 by Ext3rmin4tor »
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline romma

  • Members
  • *
Re: Help with a movement script
« Reply #2 on: 04 Feb 2009, 12:44:42 »
Thanks Ext3rmin4tor. That was very useful.

Any help with 2. would also be awesome.


Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
Re: Help with a movement script
« Reply #3 on: 04 Feb 2009, 17:52:23 »
Regarding question 2:

If the unit is a vehicle, you can use Mando_Chaser, found here:

http://www.ofpec.com/ed_depot/index.php?action=details&id=387&game=ArmA

You could use a gamelogic for the unit to be chased, and the chaser would move in a straight line to position of the gamelogic at the speed specified.

If the unit is a man, you cannot specify an exact speed.  Men move at the speeds of their animations (walk, run, sprint) and stance (prone, crouch, erect).  And their AI will make them wander off course.

However, you could write a script where you pass in direction, destination position, and animation name.  The function would then face the unit in the desired direction (dowatch or setdir), and then within a loop, you repeat the animation (walk forward for example).  The loop repeats until the distance between the unit and destination is close to zero.  You would have to also know how long it takes a unit to complete the animation, so your loop would sleep that long (otherwise a zillion playmoves would stack up, when you only needed a few playmoves to reach your destination).  This is very doable.   And would be useful for cutscenes and very controlled scripted situations.  However, in dynamic situations it can cause trouble because a playmove or switchmove can force a unit to clip through an object that blocks his path.  So if a tank is parked between a unit and his destination, he will bump into it or clip through it and look stupid.
El Cojon: "Do you like to Tango?"
You: "Only in Bagango."
Download Last Tango in Bagango and discover how El Cojon earned his name...

Offline romma

  • Members
  • *
Re: Help with a movement script
« Reply #4 on: 05 Feb 2009, 05:26:01 »
Thanks johnnyboy. I will have a play around with that.