Warning: include(/var/www/html/forum/Sources/../../../includes/depot_files/OFPEC_get_header_image.inc.php): failed to open stream: No such file or directory in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 146

Warning: include(): Failed opening '/var/www/html/forum/Sources/../../../includes/depot_files/OFPEC_get_header_image.inc.php' for inclusion (include_path='.:/usr/local/lib/php') in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 146

Notice: Undefined index: OFPEC in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 152

Notice: Trying to access array offset on value of type null in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 152

Notice: Trying to access array offset on value of type null in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 152
    Home   Help Login Register  

Author Topic: How do you calculate Velocity to move Object A to Object B in 3d space?  (Read 3362 times)

0 Members and 1 Guest are viewing this topic.

Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
Hi guys,

I am terrible at math, and would really appreciate some help.

I want a script to move Object A to Object B, in 3D space.   3D is important, so I need the Z factor calculated.

My inputs would be:

1.  Target Object
2.  Object to move
3.  Speed of Object to move.

I think I have to use SetVelocity and SetVectorDir on the Object to move, but don't know how to calculate the values.

Below is my weak attempt.

Can anybody help  me with this?

Thanks!


Code: [Select]
_target_object = _this select 0;    // target object
_vehicle = _this select 1;          // object to move to target
_speed = _this select 2;           // desired speed of object to move

_targetPos = getpos(_target_object);
_speed = speed _vehicle;

// assume vehicle is facing target
_dir = getDir _veh;

// Calculate velocity x,y,z factors
_vx = (sin _dir)*_speed;
_vy = (cos _dir)*_speed;

_vy = ????    //// How do I cacluate Y value??

// I think this is how you move the vehicle toward the target
_vehicle setVectorDir[_vx/_vh, _vy/_vh, _vz/_vh];
_vehicle setVelocity [_vx, _vy, _vz];
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 CH

  • Members
  • *
Maybe this could be of some help to you as far as the math is concerned.

If A and B are two points in space with the following coordinates…

A=(d,e,f)
B=(g,h,i)

…and AB is a vector pointing from A to B, then

AB=(g-d,h-e,i-f)=(j,k,l)

The distance between A and B or the magnitude (in your case, speed) of AB is (j²+k²+l²)^(½).
« Last Edit: 21 Jul 2010, 11:00:48 by CH »

Offline LurchiDerLurch

  • Members
  • *
My script is exactly doing this. I don't know if it's perfect (respective mathematics etc) but it works:

http://www.ofpec.com/forum/index.php?topic=34855.0

Quote
[object,target,modelToWorld,speed,distance,correct,final]spawn float;


object: the object you want to move
target: unit or position (if you pass a unit the object will follow that unit)
modelToWorld: Array position from object model space f.e: [0,5,0] is 5m in front of the target, [0,0,5] is 5m above the target
speed: Speed for rockets (f.e: 0.1 fast, 1 slow)
distance: The script will terminate at this distance to the target
correct: Correct angle to target
final: Set the object to the final position as soon as the script terminates

Helpful?

Offline johnnyboy

  • OFPEC Patron
  • ****
  • Matan los Pantalones!!!
Thanks gents! 

CH: Thanks for the mathematical solution.  That is excellent for understanding the formula.

Lurch:  Thanks for the working example!

This helps me alot.
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 CH

  • Members
  • *
Just noticed a mistake

(j²,k²,l²)^(½)

(j²+k²+l²)^(½)

sorry  :-[


Offline Gaia

  • Members
  • *
  • Bohemia Interactive Senior Game Designer
    • My personal webpage (only in Czech)
Why so serious?!
« Reply #5 on: 22 Jul 2010, 08:31:11 »
Code: [Select]
[getposasl objA,getposASL objB] call BIS_fnc_vectorFromXToY; :whistle: