Home   Help Search Login Register  

Author Topic: getdir setdir maths problem  (Read 731 times)

0 Members and 1 Guest are viewing this topic.

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
getdir setdir maths problem
« on: 21 Aug 2005, 10:40:59 »
My maths is appaling, so i would appreciate any help offered
Thx in advance

What i am trying to do is
Simulate winching a vehicle from a recovery vehicle
the particular part i am stuck with is the small incremental setdir loop that slowly turns the target vehicle to the direction of the recovery vehicle

lets play make believe

The recovery vehicle backs up (reverses) to the target vehicle
The target vehicle could be facing any direction

now what i want is for system to auto decide whether
A) the rear of the target vehicle
or
B) The front,
 should be pulled by the make believe winching rope

and this to be defined  by which end of the target vehicle is closer to the angle of the getdir of the recovery vehicle
(eg winch ropes pull, they dont push)

Once the target vehicle is roughly the same direction as the recovery vehicle, i then want to setpos it, or setvelocity it, so that the effect looks like the target vehicle is being dragged towards the recovery vehicle by the winch rope

dont worry about any other parts of the script, its just the maths bit i am stuck on

heres the rough layout

Quote
Take it that
_v is the recovery vehicle
and
_obj is the target vehicle
winch rope length = 50m
dragging speed is 1m per second
if possible it would be nice to redefine the rope length and dragging speed so a variable in there for each would be nice


#TURN_LOOP
;; dont loop faster than 0.1 seconds (its for an mp system)
~0.1
;; this loop for turning the target vehicle to face the recovery vehicle

;;once the turn process has completed, then skip the goto Turn_Loop

#DRAG LOOP
;; this loop for dragging  the target vehicle towards the recovery vehicle



Hope i aint asking too much in 1 go :)


The initial reason for this system is to reset an overturned vehicle onto its wheels, or tracks
My understanding is that, as soon as you use setdir or setpos, it will jump back onto its feet.
If by some chance, a setvelocity or some other command, can actually drag it along on its side for a bit before it jumps to its feet, that would be fantastic

(Not related to the question)
The whole system works on addaction commands attached to the recovery vehicle that the driver of the vehicle, can initiate
eg
Addaction =Recover vehicle
......Sub addaction menu..Winch Out
......Sub addaction menu..Winch In
......Sub addaction menu....Stop winching

and a drop command around the target vehicle when the winching first starts up to throw a bit of dust around

« Last Edit: 21 Aug 2005, 10:57:11 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:getdir setdir maths problem
« Reply #1 on: 30 Aug 2005, 21:50:00 »
_v == vehicle with addaction attached
Quote
#INIT
_v = _this select 0
_dist = 50
_height = 1.8
_obj = (nearestobject[(getpos _v select 0)+sin(getdir _v)*_dist,(getpos _v select 1)+cos (getdir _v)*_dist,_height])
_a = [_v,_obj] call lw_otd
_obj setdir (_a select 0)
_obj setpos [(getpos _obj select 0) + sin(_a select 0) * _pwr,(getpos _obj select 1) + cos(_a select 0) * _pwr,(getpos _obj select 2)]

and the function it calls is
Quote
Private["_o1","_o2","_x","_y","_a1","_a2"];
_o1=_this select 0;
_o2=_this select 1;
_y=(getpos _o2 select 0)-(getpos _o1 select 0);
_x=(getpos _o2 select 1)-(getpos _o1 select 1);
_a1=atan(_y/_x);
if(_x==0)then{if(_y>0)then{_a1=180}else{_a1=0}};
if(_x>0)then{_a1=_a1+180};
if(_a1<0)then{_a1=360+_a1};
_a2=acos(abs(_x/cos(_a1))/(_o2 distance _o1));
[_a1,_a2]


THREAD REOPENED
Student Pilot wanted to offer another solution
« Last Edit: 01 Sep 2005, 17:38:08 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline Pilot

  • Contributing Member
  • **
Re:getdir setdir maths problem
« Reply #2 on: 31 Aug 2005, 20:19:15 »
Quote
Student Pilot wanted to offer another solution
I didn't realize you had a solution :-[  Could you please explain how your solution works?  Thanks

Anyway, here is what I came up with.  It is most likely more complicated than it needs to be, but what's new :P

Assume _towtruck is the towtruck
_truck is the truck to be towed

Code: [Select]
_truckdir = getdir _truck
_towtruckdir = getdir _towtruck

_dir1 = _towtruckdir - _truckdir
_dir2 = _truckdir - _towtruckdir

?_dir1>270: goto "2"
?_dir2>270: goto "1"
?_dir1>180: goto "1"
?_dir2>180: goto "2"
?_dir1>90: goto "2"
?_dir2>90: goto "1"
?_dir1>=0: goto "1"
?_dir2>=0: goto "2"

hint "Student Pilot screwed up and the script doesn't work, pitch it!"
exit

#1
?((getdir _truck) - (getdir _towtruck) < 1) or ((getdir _truck) - (getdir _towtruck) < 1): _truck setdir getdir _towtruck; goto "Drag Loop"
_truck setdir (getdir _truck + .5)
~.1
goto "1"

#2
?((getdir _truck) - (getdir _towtruck) < 1) or ((getdir _truck) - (getdir _towtruck) < 1): _truck setdir getdir _towtruck; goto "Drag Loop"
_truck setdir (getdir _truck - .5)
~.1
goto "2"
I also don't know if it works in all situations, or in mp, I am still testing it out, which is hard to do without access to OFP (yeah, I am deprived of OFP, now life sucks ;D), which means I have to use paper and pencil and manually figure everything out.  Still working on it, consider this just me thinking out loud...

You didn't have to reopen the thread for me, I didn't realize you had a solution.

Btw, syntax not guarenteed.

-Student Pilot

EDIT:
Oh, wait a minute, I think I realize what you wanted.  You just wanted the line to decide which end was close, didn't you?  Well, I guess I gave you more bang for your buck ::)  I guess you can still see how I would check to see which end is closer, just ignore how I apply it then.

*Looks at Terox's method*
Hmmm, I think your way is much easier (Why,  why, WHY?!  Why do I always do things over-complicated?)
« Last Edit: 31 Aug 2005, 20:35:01 by Student Pilot »

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:getdir setdir maths problem
« Reply #3 on: 01 Sep 2005, 17:08:48 »
My initial aim of the script, was to
a) Decide which end of the target vehicle was closest to the winching vehicle and then setdir the target vehicle in small increments until it was pointing towards the recovery vehicle or 180 degrees from it

b) Once this position had been achieved, the target vehicle  would then be dragged towards the winch until X distance away

(not a towing script, a winching script)

PROBLEM
Setdir is a local command
If you setdir an object that is not local to your client, it will revert back to its original direction
You can work around this by setpos'ing the object once you have setdir'd it, as setpos is global, the object then retains its new dir on all systems

Due to the required speed of the setdir loop (which meant calling a 1 degree change every 0.1 seconds to give a smoothish movement) this would mean 10 setpos commands broadcast every 1 second
Way too heavy for the network traffic just for a realignment

and as the first setdir would reposition any overturned vehicle back onto its feet instantly anyway, so it would'nt look that realistic, i could see no point in doing this heavy setdir loop anymore

(oh if only ofp had a setpitch command)

The system now simply realigns the target vehicle so that it's front  points towards the recovery vehicle in 1 movement and then setpos's it to its own position, which allows it to keep its new dir

I have to thank LWlooser for his mathematical skills helping with  the required code

NB>> I am no longer looking for a solution, this post is in response to a query
« Last Edit: 01 Sep 2005, 17:11:09 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123