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.
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.
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.
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.