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 / terrain collision

Author
Message
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 1st Sep 2012 13:02
Hello,

Please help me with a sollution for terrain collision:

I made a terrain in 3dws, exported in dbpro as dbo object.

In my game, I shoot an arrow which go through the land.

I used this:

if Object Position Y(3300) < Get terrain Height(1,object position x(3300),object position z(3300)) then goto hitobj


I have an error: Terrain does not exist...

So...what can I do???

I dont have a matrix as terrain, it's an object created in 3dws

Please help !!

Mihai
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 1st Sep 2012 13:44
get terrain height only works with terrains created using make terrain.

If you're using your own mesh you'll have to view the terrain as another object.
What you want to use to retrieve the height at any point of an object is raycasting (you can search for it, there are probably several threads around).
The built-in function of dbpro for doing that is called intersect object; there are probably other implementations that are faster though, given certain setup, for example the raycasting in sparky's collision library.


"Why do programmers get Halloween and Christmas mixed up?"
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 1st Sep 2012 14:44
Did I see a goto in there? Ew! Horrible!

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 1st Sep 2012 19:24
Change this:

Quote: "then goto hitobj"


to a GOSUB instead and return...

and yeah using Ray Casting as Rudolpho mentioned should simplify this process... you call a ray cast and where it makes contact you then read that contact position data...

mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 1st Sep 2012 22:05
Thank you a lot,

I know it's preferable with gosub, it was just a try..
)

anyway, tx for your support

Mihai
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 1st Sep 2012 22:23
Where can I find a detailed documentation about ray casting???

I searched ..but didnt find something for beginners in this field, I want to understand the bases..........to make a good job.

Thank you

Mihai
Kezzla
17
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 1st Sep 2012 23:13
I don't think you need raycasting for terrain collision, it would be as simple as detecting collision between player and terrain and if collision = 1 then moving player object up one unit. that would give you pretty good terrain collision.

Sometimes I like to use words out of contents
xMainStar
14
Years of Service
User Offline
Joined: 26th Jun 2012
Location: Barcelona, Spain
Posted: 1st Sep 2012 23:44
I think i can help if a tps(Third person shooter), i do the collision script with sc(Sparkys Collision dll):



If the game is a fps i recommend to put a object as benchmark for the collisionslide and position the camera between the gun and the player object

Link for the sparky's collision : http://forum.thegamecreators.com/?m=forum_view&t=74762&b=5

xMainStar

I don't need what you need
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 2nd Sep 2012 01:02 Edited at: 2nd Sep 2012 01:02
Ray casting is the best way to go. I recommend searching the forum for "collision DLL" and installing the plugin, this would be the code for height detection:



Alternately, if you're too lazy to get the plugin and want much slower code, you can use the built in method (untested):



TheComet

"if you don't understand recursion than you probably don't understand recursion." ~Jerico2day
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 2nd Sep 2012 08:44
Thank you all !!

It's working very well !!!

I downloaded the sparky dll, I used this option and it's perfect!!!!

Thank you again !!!!

Mihai

Login to post a reply

Server time is: 2026-07-07 12:07:01
Your offset time is: 2026-07-07 12:07:01