Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / RTS box selection

Author
Message
Zynic
19
Years of Service
User Offline
Joined: 25th Oct 2006
Location:
Posted: 18th Mar 2007 21:40
ok so im making an RTS and i need a selection with a box. i kinda suck at coding and so i tried to make it so that if you clicked with the left mouse button it would make a box and then, as long as you held down the left mouse button, it would make the box bigger or smaller if you moved the mouse and any of your units inside of the box would be selected to move. well my little code didn't work...tried out simple with making a box but then it says that the box has already been made. oh and i need the box to be where the mouse is and all...if you can help me out i'd appreciate it. thanks
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th Mar 2007 10:00
Is this for 2D or 3D unit selection? Let's see your code.

TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 20th Mar 2007 18:04
Here's a very basic 3D version I did a while back.

You could adapt it for your program if it's any use to you.



TDK_Man

Zynic
19
Years of Service
User Offline
Joined: 25th Oct 2006
Location:
Posted: 21st Mar 2007 03:40
@ Phaelax oh im so sorry its 3D and it sucks lol...

@ TDK uhm this helps a lot but the code freezes the game at times and its a bit funkah...but its better than nothing and i'm gonna see if i cn evolve it for my needs thanks!

oh and i have this waypoint stuff where i right click and it drops a cube there and the unit that is selected will be moving towards it...theres a problem with this though and its not really the waypoints problem. see when i want to right click again and have the waypoint go somewhere else but it doesn't work cause if i click it again it either stays there in one variant or the other one it never drops cause i can't get it to work properly with the same button. i had to use right click to drop and CTRL+right click to pick up and thats tedious...

Thats kinda confusing so heres a shorter version. i can't get the same button to do two different things at different times. can't get it to drop at one spot and then later drop at another using the same button. sry it was so long.
luke810
19
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 21st Mar 2007 05:04
I'm currently working on an RTS game also and this is how I set up my unit selection routine.

The Get_Units command would search for all units on the playing field that have an Object Screen X() and Object Screen Y() between ulx,uly,mousex() and mousey() and then set those units as selected.

The Get_Unit function would search through the units until it finds one with an on screen position that is close to the mouse position. If you use this method you should keep in mind that objects farther away could be selected even if the mouse isnt on them.



Your explanation of your second problem is hard to understand so it would help if you posted that section of your code.
Zynic
19
Years of Service
User Offline
Joined: 25th Oct 2006
Location:
Posted: 22nd Mar 2007 02:10
well see theres no actual code that'll explain what im trying to do cause i changed it because it wouldn't work buuuuuuut...it seems you might've figured it out for me by accident lol...but i haven't tried your code yet so i'll explain it again maybe simpler.

I want to click on the right mouseclick to set a waypoint for units to walk to...and then i want to pick another place to set the same waypoint later which happens often in an RTS. problem is that it won't move if i use the same button. if i use a different button like say CTRL+mouseclick()=2 like i am currently, it will work but if i use mouseclick()=2 to position object and then mouseclick()=2 again to position it somewhere else it won't work. i hope that explains it better.
Zynic
19
Years of Service
User Offline
Joined: 25th Oct 2006
Location:
Posted: 23rd Mar 2007 02:51
@luke810
well your code looks good but for some reason DBC wouldn't accept

get_units(ulx,uly,mousex(),mousey() )
else
get_unit(mousex(),mousey() )

and looking at it, i kinda realize that i don't get what its supposed to be so i can't fix it or something.
TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 23rd Mar 2007 19:55 Edited at: 23rd Mar 2007 19:56
Quote: "well your code looks good but for some reason DBC wouldn't accept"


luke810 didn't supply the functions get_units() and get_unit().

However he told you what they needed to do so you could write them yourself.

As for my code, it's never frozen for me before and I'm not familiar with the term 'funkah' so wouldn't know what to suggest.

TDK_Man

RUCCUS
21
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 25th Mar 2007 06:48
Simple but effective method of RTS-3D-box selection:

- Once you've got the box coordinates on-screen of each corner
- Convert the coordinates to 3D
- Get the distance between the top 2 coordinates and the distance between the left 2 coordinates. Make a box out of this with a large z scale
- Check for box collision with all units and the newly formed box

2D-3D position conversion can be done using pick screen and the get pick vector xyz commands. Box collision can be as simple as using a few automatic object collision commands.

TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 9th Apr 2007 07:56
Quote: "2D-3D position conversion can be done using pick screen and the get pick vector xyz commands. Box collision can be as simple as using a few automatic object collision commands."


Not quite so easy when you are using DB Classic!

TDK_Man

C_Coffie
19
Years of Service
User Offline
Joined: 31st Oct 2006
Location: CANDY LAND
Posted: 11th May 2007 02:28
hey i tried making a rts from this one tutorial i dont remember which on i got this

then he stoped the tutorial and there was nothing else i was wondering if you guys could tell me where to put the selection box in the code because im a beginner and also which one?
thx in advance

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 12th May 2007 00:23
I've seen a few ppl do mouse clicking on a matrix by positioning an object. I think thats just a poor solution. (no offense intended to anyone)

It might've been my tutorial, im not aware of any other rts tutorials. I stopped doing a classic version because I moved onto DBP at that time and the new features made things easier.

Use right-click to get matrix coordinates at mouse, hold left-click to select objects. The mouse to matrix routine only works for a flat matrix and I'm not sure who the original author was. There's another method you can use but requires the enhancements for memblocks.




I still have the DBC code I started for the RTS.
http://zimnox.com/?page=dbTutorials


TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th May 2007 01:30
Quote: "Use right-click to get matrix coordinates at mouse"


And that is the problem with DB Classic - it's not easy when all you've got is the Object Screen command.

The code I posted above I admit is a 'kludge' for DB Classic, but it's a working one. If I find a better way, I'd be the first to switch to using it!

But, the snippet is just one I did quickly to demonstrate the idea and if I used it myself, I'd improve the rectangle drawing side of things.

However, in a nutshell, I'd have to agree with Phaelax that it would be better not to attempt an RTS with Classic - DB Pro is a far better idea...

TDK_Man

luke810
19
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 12th May 2007 05:39
@Phaelex

I am working on an RTS game for DB Classix and I have a perfectly good function for finding the position of the mouse on unflat matrices that can also be used to make a simple select object function using raycasting.

I also want to say that I think the way TDK and Phaelex described how hard it is to make a functioning RTS game in Classic is a bit extreme. It would definetly be easier in DB Pro, but with some skillfull programming you can get the same results as alot of DB Pro functions using DBC.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 12th May 2007 17:34
Not saying its impossible, I had a decent start on a DBC version myself. But it sure will be a bit tougher, so more power to you.

If you can calculate the view matrix of the camera, you should be able to transform object 3D coordinates into 2D. Thus you wouldn't have to rely on "object screen" command and could instead define a small 2D box around the character, making for more accurate selection. I think Dmitry would have a better idea at this sort of math.


TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th May 2007 17:43
Quote: "I also want to say that I think the way TDK and Phaelex described how hard it is to make a functioning RTS game in Classic is a bit extreme"


I was only saying that it's quite hard doing it in DBC the same way as in DBP as you don't have all the commands you have in DBP.

My comments about it being better to use DBP were aimed at a beginner - because of the additional commands available. Raycasting is a more advanced subject for someone with a bit more programming experience.

It obviously is possible to do it in DBC as my snippet earlier in the thread showed - however bad the snippet actually was!

But on the whole, I totally agree with you - with some skillful programming you can get the same results as a lot of DB Pro functions using DBC.

TDK_Man

C_Coffie
19
Years of Service
User Offline
Joined: 31st Oct 2006
Location: CANDY LAND
Posted: 14th May 2007 04:10
i used dbp not db i was just on it because this is where i thuoght i would find the help. Phaelax it wasnt you tut. i tried yours but it was way to cofusing. but any of you got an idea on how i can do mine and also mine is dbp. thx so much

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th May 2007 04:37
If you have a similar but is DBP-related, you should really post in a new thread under the DBP board.


TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 14th May 2007 05:19 Edited at: 14th May 2007 05:24
At the risk of being accused of shamelessly plugging TGPF, (which I am because we need new users), I've just put a whole load of updated code snippets on there (including a new improved version of this one).

Anyone else with useful snippets is also welcome to post theirs too!

Link to TGPF in my sig below.

TDK_Man

Login to post a reply

Server time is: 2026-07-05 18:39:16
Your offset time is: 2026-07-05 18:39:16