-
Movement calculation
I would like to make a system for moving things using position actions. I know how I want it to work but I can't calculate how to do it on my own.
The way I want it to work sounds quite simple. I need the character to be able to move towards a set of coordinates in a straight line, meaning I'd have to calculate how far ,in x and y, the character would have to move in relevance to the final coordinates and also depending on the character's speed.
For example, target is at coordinates 40x40 and the character is at 80x80. For every step towards these coordinates he'd move x-4 y-4, if his speed was 4. However, like I've said I have no idea how to put that into an expression.
Btw, is there an object that can calculate the distance between two objects like that old RTS object could?
-
Re: Movement calculation
holy cow don't make an easy thing complicated! put another active object at the target, tell your object you want to move there to always -> look at (active)then... object overlaps active -> stop.
-
Re: Movement calculation
That would work, but it's not reall a straight line (since the object only moves in 32 directions)--unless you don't mind this?
-
Re: Movement calculation
Clickteam's Movement Controller can calculate the distance for you. Check your extensions list, you should find it there.
-
Re: Movement calculation
Popcorn: Thanks for the suggestion!
As for using another object to guide the character in a straight path, that's what I'm already using, but it's not very efficient. A calculation would save on the game performance by using less objects and I would also have other uses for the calculation.
-
Re: Movement calculation
This algorithm was suggested to me by a programmer friend:
http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
This would work perfectly for checking a line between two points for obstacles. I'd use the optimisation bit I presume. Problem is, MMF doesn't use boolean (extension, perhaps?) and there are no swap functions. How would this look in MMF2's event editor? Any experts?