The Daily Click ::. Forums ::. Klik Coding Help ::. Moving an object towards a particular object
 

Post Reply  Post Oekaki 
 

Posted By Message

Heart Break Kid



Registered
  13/05/2003
Points
  1754
26th January, 2007 at 13:10:09 -

If i need to move an active object towards a target then i'll set ball movement for the object to be moved and set its direction towards the target to make it move towards it. But with this technique few times the active object misses its target.

Any other ways to do the same thing?

 
(\__/)
(='.'=This is Bunny. Copy and paste Bunny into ur
(")_(")signature to help him gain world domination.

Klik with the kid!

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
26th January, 2007 at 13:48:05 -

Distance to move = (sqrt((x2-x1)² + (y2-y1)²))

You'll probably have to use decimals, if so, times by 1.0.

Angle to move = atan((Y2-y1)/(x2-x1) (I think mmf Gives you it in radians. If this is the case, change it to degrees using (angle * 180/pi)you might need to add or subtract 180 degrees, depending on the position of the moving object relative to the target object Again decimals are probably needed.)

Set angle to angle to move. Move (Distance) pixels.

The only real way to ensure is to constantly look at the centre of the object whilst moving, that way it will auto adjust whislt moving along the path.

 
My signature is never too big!!!

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
26th January, 2007 at 15:13:34 -

Or if you can't be arsed to use any advanced math, you can use the MoveIt object. It's perfect for this sort of tasks.

 
n/a

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
26th January, 2007 at 15:34:12 -

Advanced maths?

LOL

Trust me, that's not advanced.

 
My signature is never too big!!!

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
26th January, 2007 at 16:25:58 -

Yeah yeah, but for him it's advanced.

 
n/a

Heart Break Kid



Registered
  13/05/2003
Points
  1754
26th January, 2007 at 22:40:52 -

I'am using TGF, i don't think i can even apply these 'advanced methods' on it. PS MoveIt object is again, for MMF.

Image Edited by the Author.

 
(\__/)
(='.'=This is Bunny. Copy and paste Bunny into ur
(")_(")signature to help him gain world domination.

Klik with the kid!

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
27th January, 2007 at 06:10:42 -

I'm pretty sure TGF has the Square root function, and atan function.

If not.

http://www.clickteam.info/extensions/extview.php?id=37
Get the advanced math object

 
My signature is never too big!!!

Heart Break Kid



Registered
  13/05/2003
Points
  1754
27th January, 2007 at 10:14:49 -

One simple thing i tried before was to simply force the moving object to face the center direction of the target i.e. Always look at the target but this would create much of a trembling effect when the ball movement is directing object somewhere else and the always event keeps on changing its direction exactly to the target. So this method didn't work either.
MoveIt object isn't available for TGF yet and i need to use a totally separate object besides using that math to get the job done. I prefer keeping it as simple as possible, are there any other alternate ways, extensions?

 
(\__/)
(='.'=This is Bunny. Copy and paste Bunny into ur
(")_(")signature to help him gain world domination.

Klik with the kid!

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
27th January, 2007 at 10:31:06 -

To do it effectively, you'd need 360° movement (not the 32 directions TGF offers).
You could try
- Getting the distance in pixels to the target object
- Starting the movement, look at the centre of target
- Every (Distance/Checks) pixels, look at the centre of the object again. (The checks is the number of times you want to look towards the object. Don't have it too high, but don't have it too low either. Your best bet is to work on an algorithm to calculate the number of steps. The most basic algorithm i could think of is (Distance to move/Width of object) this would mean that every time it moves it's width, it looks in the centre of the target again.)

This will still create a shakey movement, but it won't be as shakey as you're not constantly changing direction, you're only changing direction every so often.

Image Edited by the Author.

 
My signature is never too big!!!
   

Post Reply



 



Advertisement

Worth A Click