Home   Help Search Login Register  

Author Topic: Helo Movement without AI  (Read 2104 times)

0 Members and 1 Guest are viewing this topic.

Homefry31464

  • Guest
Helo Movement without AI
« on: 21 Jul 2005, 00:44:43 »
This script is for guiding a helicopter from one point to another using the setpos command... effectively bypassing the AI's control.  It has room for improvement... I plan on adding in somewhat dynamic directional movement and pitch... among other things.  

Code: [Select]
';Call Using [unitname,startobject,endobject,duration,groupincargo,landtrue]
;For landtrue, 1 is considered true (not the word true!)
;For landings, I recommend an invisible H being the end object
;The objects (I recommend game logics for objects) must have their height set by setpos or other.
;Duration is in seconds (Duh! :-p)
;Amos Scott(Homefry)

;Retrieve starting values
_unit = _this select 0
_startObj = _this select 1
_endObj = _this select 2
_duration = _this select 3
_cargogrp = _this select 4
_landtrue = _this select 5
_i = 0
;Set Correct Helo Direction
_unit setdir getdir _endObj

;Calculate movement/decent rates
_ratex = ((getpos _startObj select 0)-(getpos _endObj select 0))/(_duration / .01)
_ratey = ((getpos _startObj select 1)-(getpos _endObj select 1))/(_duration / .01)
_ratez = ((getpos _startObj select 2)-(getpos _endObj select 2))/(_duration / .01)

;Set Starting Coords
_currx = getpos _startObj select 0
hint format ["%1",_currx]
_curry = getpos _startObj select 1
_currz = getpos _startObj select 2

;Start Movement Loop
#move
_currx = _currx - _ratex
_curry = _curry - _ratey
_currz = _currz - _ratez
;_newpos = [_currx, _curry, _currz]
_unit setpos [_currx, _curry, _currz]
_unit setdir getdir _endObj
_i = _i + 1
?(_i >= (_duration / .01)):goto "landers"
~.01
goto "move"

;Begins the disembarking of troops
#landers
?(_landtrue == 0):exit
_aunits = units _cargogrp
_i = 0
_j = count _aunits
goto "lander"

;Disembarks units
#lander
?(count crew _unit == 2):exit
_unit setpos [_currx, _curry, _currz]
~.01
(_aunits select _i) action ["EJECT",_vehicle]
unassignvehicle (_aunits select _i)
_i=_i+1
?_j>_i:goto "lander"

exit

DO NOTE:
This script relies on the first object to be placed in the air... I recommend a game logic.  I am planning on making this easier... for example allowing the player to just place a marker... then having the starting height of the chopper settable when calling the script.

Also... I would try to estimate the distance of the objects when considering a duration.  Just take the estimated distance... then divide by a duration.  I recommend you aim for around 30-45 to be your result (speed in meters/second).

Any and all feedback would be great.
« Last Edit: 21 Jul 2005, 16:07:32 by Homefry »

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Helo Movement without AI
« Reply #1 on: 21 Jul 2005, 01:54:36 »
i notice that it sets the chopper to the same direction as the end chopper

perhaps instead you should use a dirtopos function or dirtoobj function, otherwise the editor would have to set the direction of the end object to work right for the chopper

or did i miss something?

Homefry31464

  • Guest
Re:Helo Movement without AI
« Reply #2 on: 21 Jul 2005, 02:29:47 »
No... you are correct.  I simply did this because it was simple at the time... I made it in 5 minutes or so and at work... and I had to figure out a simple way to set the helo's direction...

Homefry31464

  • Guest
Re:Helo Movement without AI
« Reply #3 on: 21 Jul 2005, 16:04:14 »
The opening thread has been updated to have all the current updates.  I also posted a test mission... for those to lazy to test it out themselves..  :P

Offline Blip

  • Members
  • *
  • ...Old OFP FART...
Re:Helo Movement without AI
« Reply #4 on: 22 Jul 2005, 01:19:30 »
Works good!

I was going to try and make something like this up myself this afternoon.  I'm glad I took a look here first.  ;D

Would it be alright homefry if I used your helimove scripts in my boat rappel scripts I am working on.  I need to be able to align the helo up with the boat from a distance and these scripts are making it real easy.  Looks good too!

Thanks,

Blip :joystick:
...NIGHT WALKER....

Homefry31464

  • Guest
Re:Helo Movement without AI
« Reply #5 on: 22 Jul 2005, 04:23:31 »
Works good!

I was going to try and make something like this up myself this afternoon.  I'm glad I took a look here first.  ;D

Would it be alright homefry if I used your helimove scripts in my boat rappel scripts I am working on.  I need to be able to align the helo up with the boat from a distance and these scripts are making it real easy.  Looks good too!

Thanks,

Blip :joystick:

Thanks for the feedback and kind works Blip.  Sure you can use this... modify it, do whatever you'd like.  I'm interested in the boat rappel scripts... what does that do exactly?

NOTE:  In the example mission... you have to call the script to start it --> Radio Alpha.

Offline Blip

  • Members
  • *
  • ...Old OFP FART...
Re:Helo Movement without AI
« Reply #6 on: 22 Jul 2005, 04:27:54 »
Thanks Homefry!

For info on the boat rappel scripts go here.

I need your scripts to make it so a player can call for a boat rappel from anywhere on the map, and the helo will fly to the moving boat exactly.

Check out the example mission, you'll get the idea.

Blip :joystick:
...NIGHT WALKER....

ROBINO

  • Guest
Re:Helo Movement without AI
« Reply #7 on: 23 Jul 2005, 12:32:22 »
hey homefry

I succeeded in using escplicit movement commands in the script i created to call an AI controlled chopper around the map to perform a number of actions.

I found that over large distances its best to let the AI control the chopper, but while approaching the landing zone the script takes over and by using a conbination of setvelocity and setdir I accurately positioned the chopper to a point 30m above the Helipad.  Landing in this way means the chopper hits the LZ every time and removes any chances of overshoot.

Here is a link to the thread:
http://www.ofpec.com/yabbse/index.php?board=27;action=display;threadid=23120