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 Professional Discussion / Ship movement spherecast avoid collision - code

Author
Message
Ben_UK78
16
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 8th Feb 2011 02:51
I've never put my code up here before, so I'm not sure how to do it properly.

This is my solution to a previous problem I asked regarding having ships avoid obstacles in a space based RTS.

You can add up to 50 objects and the moving ship will steer around them... generally - you can give it headaches if you box it in - it only goes left and right after all and isn't intelligent.

The object spherecasts around itself looking for free paths either left or right and, upon finding one, steers in that direction. Its 700ish lines though, but not all of it is necessary just to steer it, some is because it is intended to fit into a bigger project.

It also features code for dragging objects using the mouse, rotating to objects and world coordinates, distances using vectors as well as loading and saving stored object positions to store and test weaknesses in it when I want to improve it later on.

I've made it as not a bad starting position in building space based direction finding (though it might work fine like this if not too boxed in). It isn't as small as it could be, but it is easier to understand like this.

Finally - to the Mods: It is part of a bigger program. I often start projects and fail to get too far as I get bored or stuck writing the base engine - loading, movement, weapons fire etc. This bit of code almost adds the final touch to my bigger project. It now does much of what a space RTS should do. Mouse click movement, context sensitive mouseclicks, homeworld style 3d or fixed birdseye cameras, bullet fire, missile fire, beam weapon fire, radar, much loading (game details, sector details, ship details, station details) based on text files etc. It has rudimentary AI - go to world coordinates, attack object etc. No graphical implementations. Just the very basics of the boring bit to build a space RTS game ontop of. It is about 8000 lines of code with all the functions for doing the above and more. My intention was always to stick it on here somewhere once it could do all the basics I wanted. How would I go about doing that when I am ready?

Regards to all

Ben
Wyldhunt
16
Years of Service
User Offline
Joined: 27th Sep 2009
Location: The Dark Side
Posted: 8th Feb 2011 10:41
I may not be a mod, but I know of at least one place that you could put this one part and, later, all of it.

http://www.thegamecreators.com/?m=codebase_list

In the codebase. That way, it won't get buried and lost.
It's not very often that someone volunteers this much code. It would be a shame to lose it.

Thanks for posting this.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Feb 2011 10:53
That's some really great code Ben!

It works really well and without the 'Math' shown looks very smooth.

You can show your code like this:


...by putting it between two boxes like this (just take the dots out):
[.code lang=dbp]your code here[./code]

Ben_UK78
16
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 9th Feb 2011 22:59
Thanks very much.

I'll add it to the codebase when I get a chance, and thanks for showing how to add code in the block. Obviously i've seen it done that way, but I wasn't sure how much you could put in like that. Admittedly I could have just tried!

The bigger piece of code, my 'engine' (as it is) will be stuck up here at some point - but might be a while. I'm only doing it for fun and as a bit of a challenge. I've got a bit more to add, though i'm on to the simpler stuff now it can move ships without crashing them into each other and stations, handle polygon bullet missile and beam weapon impacts on the shields and hulls (those have been this months fun!). My aim is to have a platform that can be built upon easily in either a Homeworld, top-down RTS or space ship flight simulator style. Since the code is fully 3D it is really just a case of where you manage the camera after all. So when I have an idea in the future it will be a base from which I start, then I just put the game and graphics/models on top and never have to program this bit again. Thats the idea anyway. Next job - a better screen for selecting ships/stations/planets in a sector, ah back to the radar code again...

Thanks for the help
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Feb 2011 09:29
I should have said you can use the buttons at the top of the "Post Forum Message" box too!

Also an unwritten one is to add youtube videos:
[.youtube]YJc8796cKJBH[./youtube]

The code in the middle is just the bit of code at the end of a link on youtube.

Login to post a reply

Server time is: 2026-07-15 22:37:53
Your offset time is: 2026-07-15 22:37:53