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.

Newcomers DBPro Corner / need help setting up terrain object using collision

Author
Message
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 7th Dec 2012 07:37 Edited at: 7th Dec 2012 07:42
Using dbpro
I'm trying to set up grass and tree objects on my terrain but i cant use get ground height() or terrain height() cause im not using a matrix or mesh terrain. Using a .dbo object that is definitely not flat. Been using sparkys collision for my main player.So far been starting off objects above ground and moving them down in a loop until they collide and positioning them at that point. having trouble detecting the collisions dont understand sparks coding

this is kinda what my code looks like atm


tried slowly incrementing it down as well

A child's dream never dies.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 7th Dec 2012 10:25


That should work.

Why are you doing this?



next will already increment it for you.

TheComet

Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 7th Dec 2012 19:06 Edited at: 7th Dec 2012 19:13
I was just making a new project and ran into some "Player On Ground Checking" issues, to try and make my player jump. Anyway I came up with this. (TheComet is right btw)



This will cast a ray between the player X/Y/Z coordinates and the sphere I've created that is placed under the player.

"Collide_Ground" will return the object number it is hit with.

The first 0 means it will check every single object that is properly setup with sparkys DLL - SC_SetupObject or SC_SetupComplexObject followed by the object ID.
The last 0 means it will not exclude any object.

You can also get the collision distance by using other commands. I suggest you look into the help files. It's pretty hard to understand at first, but once you get the hang of it you'd be "Oooooh.. "
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 8th Dec 2012 19:44
Thank u comet,code works like a charm. Had alot of trouble with db built in collision commands, first time i've gotten far enough in a project to need collision.a lot of trial and error so far.

A child's dream never dies.
Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 12th Dec 2012 15:38 Edited at: 12th Dec 2012 18:44
Good to know it's working smerf.

Question, in a strategy game like Command and Conquer, where the player can place buildings in a 3D world, how would one be able to get this working?





It would be neat, if you could
A) Calculate the height of the terrain from these world coordinates, and place the object there.

B) Adjust the distance real time, as it's set to 1000 right now, all objects will be placed at 1000 units away from the camera.



LMAO! I forgot to put the the command "SC_UpdateObject" in a loop.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 13th Dec 2012 21:20
A) Do the same as above:



B) Distance from the camera?

TheComet

Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 14th Dec 2012 10:22 Edited at: 14th Dec 2012 12:54
This is the current code. I will uploade a ZIP file with the executable inside.



I'm using "Control Camera Using ArrowKeys 0,10,10"
When pressing the upkey or downkey , the Camera.Xpos changes to something unlimited. The sphere is flickering, changes from unlimited range to the collision range. And, when the sphere is not flickering the Y-Height of the placed object change every time you place something by a very small amount. The sphere height is not correct.

Press "Space" to go up and "C" to go down. Use the mouse to move the sphere around, use the up and down key to move the camera. And "W" to place an object.

Press "E" to increase the Xposition of the plane, and "Q" to decrease the position.

Using "SC_GetCollisionSlideY()" is not working, it will be placed at an unlimited range.



This is the best result so far :



Checking collision between the 2D -> 3D mouse coordinates and 50.000 units away from it (High value to make sure it can not get above the terrain).
The objects place at the correct height.

Attachments

Login to view attachments
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 15th Dec 2012 11:23 Edited at: 15th Dec 2012 11:24
Your program didn't run because it uses a display mode larger than what my laptop can support.

Looking at your code, I don't quite see what you're trying to do. I'm assuming you just want to position the Game_Sphere where the mouse is clicking on the terrain?



pick object will allow you to find where the mouse is clicking on Terrain_Obj.

TheComet

Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 17th Dec 2012 10:29
Right, I've updated the screen to 1024x768-Windowed and attached it.

I want to place and move around a sphere on the terrain, at the mouse coordinates.


In the next snippet, I set Distance#1 to be a constant value. By doing this, I can "cast a ray" from the mouse 2D position, to the 3D point. Also, this makes sure I will always collide with the ground. Because the camera can never be zoomed out that far.



Then, by using Sparky's DLL. I will cast a ray from the Camera position, to the above vector positions.



I will then get the collision distance in a new variable.


Next, use a second pick screen command, but this time it will use the collision distance.


Having all of this, I can place a sphere in the world on the terrain.




It is probably far away from the best approach, but it's working(for now atleast). Using a messy bit of test code, I'm now able to hover over a high quality sprite :lol: and press a key to let an object position in the 3D world according to my mouse position. Then when I press another key I can place the object.


First hold space for a few seconds, so the camera will go above the terrain. The 2 sprites are on the left, colored as a rainbow.
When the mouse is on the "Command Center" sprite press "\" or "|" (Keystate 43). You will then see a box positioned at the sphere. When you press "]" or "}" (Keystate 27) you can place the object in the world.

Attachments

Login to view attachments
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 17th Dec 2012 11:40
Did you look at my last code snippet? That's exactly what you want with only 6 lines of code.

TheComet

Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 17th Dec 2012 13:46
Hi again TheComet,

I've used your code in a few different ways, but it does not work.



The sphere stands at 0,0,0 and does absolutely nothing.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 17th Dec 2012 23:52
Don't know what you're doing, but it works fine for me:



TheComet

Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 18th Dec 2012 09:48 Edited at: 18th Dec 2012 13:06
Sigh, thank you TheComet. I was doubting you understood what I wanted, but it's working now.

Copying your last code snippet directly into my game didn't work (I've changed the variables to the correct object numbers).

The problem wasn't anywhere in my(last pieces of code) or your code. I created a new project, and tested your last piece of code and it worked fine.

I've created a new project, copy/pasted my own code into that.. and now it works!? Strange you would say, but I've had this problem before.. Took me days to finally copy and past my whole code into a new project, and mysterious powers that come deep out of the cybergalaxy made the game work.

I just have to keep myself away from the idea to copy/past my code into a new project if I run into an error again..

Login to post a reply

Server time is: 2024-11-21 18:36:38
Your offset time is: 2024-11-21 18:36:38