Home   Help Search Login Register  

Author Topic: Moving an object from point A to B  (Read 1542 times)

0 Members and 1 Guest are viewing this topic.

Offline D.murphy man

  • Members
  • *
  • I'm a llama!
Moving an object from point A to B
« on: 20 Aug 2008, 09:20:54 »
Hey all,

I have been doing some searches and trying to scrape together a solution for this a while now but i have yet to find exactly what i am looking for.

What i simple want to do is get an object (in my case a gamelogic) to travel (slowly) between two markers like so:

A.  GL move from here
   \
     \ 
       \
         \
            B.  To here, at walking pace.

Now even thou this sounds simple, it seems it could be a complex math question. Id imagine it would involve getting the direction of B from A and the distance, then sending the object in said direction one bit at a time. This is way over my head being a complete failure at maths.

Cheers all.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Moving an object from point A to B
« Reply #1 on: 20 Aug 2008, 12:43:49 »
Well, you could work out all the maths, but why not be lazy! Create a camera, animate the camera and then setPos the logic to the camera's position every frame:
Code: (moveFromAToB.sqf) [Select]
// [_logic, markerPos "A", markerPos "B", 5] execVM "moveFromAToB.sqf";
// or
// moveFromAToB = compile preprocessFileLineNumbers "moveFromAToB.sqf";
// [_logic, markerPos "A", markerPos "B", 5] spawn moveFromAToB;
//
_object = _this select 0; // Object to move.
_a = _this select 1; // Initial position.
_b = _this select 2; // Final position.
_speed = _this select 3; // km/h

_speed = _speed / 3.6; // Convert to m/s
_distance = _a distance _b;

// Create a camera and animate it along the path.
_camera = "camera" camCreate _a;
_camera camSetPos _b;
_camera camCommit (_distance / _speed);

// Keep the object moving along the path
waitUntil
{
_object setPos (getPos _camera);

camCommitted _camera; // Waituntil
};

camDestroy _camera;

This opens up a lot more options to you, even if you aren't a maths wiz, by using the simple cam* animation commands to move the camera. Obviously, writing the maths for yourself will be more versatile if you are a mathematician, but if you ain't, these methods will get you a long way...
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline D.murphy man

  • Members
  • *
  • I'm a llama!
Re: Moving an object from point A to B
« Reply #2 on: 20 Aug 2008, 14:19:58 »
Thanks Spooner! worked like a charm.

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Moving an object from point A to B
« Reply #3 on: 20 Aug 2008, 14:55:53 »
Clever! I remember using cameras to calculate relative positions before the modelToWorld command, by using camSetRelPos  :D Yay for hacky workarounds! Who needs math?

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline Crowey

  • Members
  • *
Re: Moving an object from point A to B
« Reply #4 on: 20 Aug 2008, 15:36:40 »
Prob a really daft question but am new to all this why would you want to move the game logic? what does it do?

Offline D.murphy man

  • Members
  • *
  • I'm a llama!
Re: Moving an object from point A to B
« Reply #5 on: 20 Aug 2008, 15:57:10 »
Gamelogics are handy for numerous things like marking a location to use in a script (with getpos), there basically invisible objects. In my case i am using them to simulate the movement of zombie hordes, as the gamelogic moves so does the zombie spawn trigger. If any players come by to check out the horde (since its marked on the map) all zombies start spawning in the area. Thats the general gist of what im doing any way, i dont fancy typing it all up in detail.