CodeRecipe( );

one stop for all game coders..

For better display use Firefox Browser.Simply go to: GetFirefox.com
Follow us on Twitter
Home
RTS game creation Print E-mail
User Rating: / 3
PoorBest 
Written by CR Team   
Saturday, 18 July 2009 08:27

Lot of questions on writing RTS ( Real time strategy ) games for a browser involving 3D. So the post dedicated o answering/clearing few doubts. 2 specific one’s listed below:joystick

Thanks for answering my RTS question quickly. it is coming along I am having trouble with moving units via mouse click (click a unit click a empty space unit moves there) I know that vectors are important but I can’t seem to find a way to make it work so any sites or help would be a great help. Great site by the way - Nick, sckans.edu

I’m making a game were the user controls one character (in this case a large rat) by selecting it by clicking it and then clicks were they want the character to go I tried locV and locH but it dose not seem to work right how do I go about solving this problem?

You can use the rayCastAll() and the rayCastClosest() function in physics to help you solve your problem to some extent.
You can cast a ray from your camera position to the model, followed by raycast to the new position, and thus move the model.

Find the distance and direction using the distance formula and  vector math.
OR
an old school method would be to use modelsUnderLoc() method of camera.

eg: Suppose your 3D sprite name is my3dsprite.

1
2
3
pt = the mouseLoc - point(sprite(”my3dsprite”).left, sprite(”my3dsprite”).top)
models_list = sprite(”my3dsprite”).camera.modelsUnderLoc(pt, #detailed)
--The list would contain all the models under the line of mouse click :)

 

You can also use a combination of modelsUnderLoc() and Raycast functions from physics engine for performance gains.

Pickup a good vector math book and start reading it. lot of problems can be solved with the help of raycasting and vector math !

Some examples for RTS games would be :

World of Warcraft , Age of Empires etc.. more…