Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Game Programming in C, Question about strategic games

Hi,

don't we all love real-time strategic-games like

command&conquer or starquest? I wanted to programm

such a game and coded foundatations, but just i completed this there was the question how to implement

a function that calculates dynamically how an object

must move from a to b via c. Where c can change all

the time.


Can you help me?

Every idea welcome.


Thanks in advange


Christian Linnemann

c-linnemann@gmx.de

GERMANY




Comments

  • I read your question a few hours ago and pondered it for a while, here's what I came up with:


    1) Take your two points, A and B.

    2) Calculate the midpoint between them [(Ax + Bx)/2, (Ay + By) /2] and call it point C.

    3) Find the normal to vector AB.

    4) Move point C in the direction of that vector, or it's opposite direction, until one or the other reaches an empty space that is a pre-defined minimum distance from any obstacles.

    You now have two vectors, AC and CB. If either of these overlap with details on the map, the repeat the process describe above on it.

    This is a recursive function. you just need to keep breaking down the vector into path and smaller pieces.

    NOTE: when repeating this process, you are best to change step four _slightly_. Rather than checking in both directions, try just checking to the direction that points away from the triangle ABC. (eg. you have broken up vector AB into AC and CB, and you have move C away from line AB. If you now have to break up vector AC, you calculate it's midpoint, D, and move it along the normal to AC, but AWAY fro triangle ACB.)

    I have only tested this on paper and it's fairly sound, but not perfect.

    After you have found a path, you have to clean out redundant steps by checking between any points that are not already connected, and making sure that it actually is impossible to go on a straight line between them. If it is possible, then you can make your path go between them and throw away any points in between.


    I hope that helps!


Sign In or Register to comment.