I have a problem. I am making an RTS game, but even though I can select the units, and make them all move into co-ordinateds 0,0,0, I have not been able to work out any method to work out a 3D co-ordinate for them from the 2D mouse co-ordinate, and then make the selected units move to that part
rem the following is to handle unit selection and camera movement for an rts game
rem it's setup for just 10 "units" but the can be applied to 100's
rem setup unit selection array for 10 units
dim unit_selected(9)
rem setup 10 unit objects and place them randomly
for objectno=1 to 10
make object cube objectno,10
position object objectno,rnd(250)-125,0,rnd(250)-125
next objectno
rem set camera
camx#=0 : camz#=0
position camera camx#,200,camz#
xrotate camera 60
set camera range 100,400
rem setup sync rate
sync rate 60
sync on
do
rem mouse and arrowkey camera control
if selectbox=0 and (mousex()>screen width()-5 or rightkey()=1) then inc camx#,6
if selectbox=0 and (mousex()screen height()-5 or downkey()=1) then dec camz#,6
position camera camx#,200,camz#
rem unit selection code
if mouseclick()=1 and selectbox=0
rem deslect all units if shift keys are not pressed
if keystate(42)=0 and keystate(54)=0
for unit=0 to 9
unit_selected(unit)=0
next unit
endif
rem activate selection box
selectbox=1
selectboxstartx=mousex()
selectboxstarty=mousey()
endif
rem display selection box
if selectbox=1
if selectboxstartx=selectboxstartx and object screen x(unit+1)=selectboxstarty and object screen y(unit+1)=mousex() and object screen y(unit+1)=mousey() then unit_selected(unit)=1
if object screen x(unit+1)=mousex() and object screen y(unit+1)>=selectboxstarty and object screen y(unit+1)=selectboxstartx and object screen x(unit+1)=mousey() then unit_selected(unit)=1
next unit
selectbox=0
endif
endif
rem colour selected units red
for unit=0 to 9
if unit_selected(unit)=1
color object unit+1,rgb(255,0,0)
else
color object unit+1,rgb(255,255,255)
endif
next unit
rem gets all the units to move to the 0 co-ordinate
rem when you right click
for unit=0 to 9
if unit_selected(unit)=1
if mouseclick()=2
point object (unit+1),0,0,0
move object (unit+1),10
endif
endif
next unit
rem display help text
text 0,0,"Left click to select a unit"
text 0,16,"Drag a box to select multiple units"
text 0,32,"Also try selecting and deselecting units by holding shift"
sync
loop
Any help welcome
THANKS
RED GENERAL
My computer melts regulary - perhaps it likes being fondue