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 / Collision. How do I do it?

Author
Message
Thistle Studios
17
Years of Service
User Offline
Joined: 1st Mar 2007
Location: Kirkcaldy
Posted: 14th Mar 2011 21:17
Essentially my program creates a skybox and within it is my custom made .x model ship, and a spinning Earth. The ship can be rolled, yawed and pitched and the speed is variable using a 2D sprite for a speed bar which can be controlled with W and S.

I have no idea how to get the collision to work. Simple as.

Setup Function:


And "Collision" function:



Intel Core i5 3.2 GHz, 4 GB RAM, NVIDIA GeForce 9800 GT
Endangered City. An Endangered Species
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 14th Mar 2011 23:08 Edited at: 14th Mar 2011 23:09
You only need to turn the collision on to an object once unless you are turning it off in your program. You don't want your ship to collide with your skybox do you? If you don't, you should turn the collision off to object 1 (skybox). If you want to use the built in commands, I would use OBJECT COLLISION instead of OBJECT HIT.

I don't know how your ship is shaped or what polycount it is. Setting it's collision to polygons will typically give good collision, but likely it will slow down your framerate considerably, especially if it is very complex. I would suggest you use the Sparky's collision dll (found here):
http://forum.thegamecreators.com/?m=forum_view&t=74762&b=5

It is fast and it is free, and you can set up complex objects (like your ship) and get good results with a decent framerate. There are examples included with it to help you get going.

You appear to be shrinking the 'hull' graphic when the ship collides with anything (earth). You should track the hull status with a variable. Otherwise, the hull graphic will just keep getting smaller, and the ship will never explode, fall from the sky, etc.

You have nothing in your code to reposition the ship if a collision occurs.

Thistle Studios
17
Years of Service
User Offline
Joined: 1st Mar 2007
Location: Kirkcaldy
Posted: 14th Mar 2011 23:20
I'll check out the DLL tomorrow, but here is a picture of the ship I created. Unfortunately I have tried three programs in order to get a decent one, and Cartography Shop seems to do the job best since it can texture things whilst Wings 3D and Anim8or can't.

Intel Core i5 3.2 GHz, 4 GB RAM, NVIDIA GeForce 9800 GT
Endangered City. An Endangered Species

Attachments

Login to view attachments
Thistle Studios
17
Years of Service
User Offline
Joined: 1st Mar 2007
Location: Kirkcaldy
Posted: 16th Mar 2011 21:30 Edited at: 16th Mar 2011 21:37
Update. I have downloaded the DLL, but my code is still crap.

Setup Code:


Collision Testing:


And Collision Response:


EDIT: BASIC COLLISION! Yay!

Intel Core i5 3.2 GHz, 4 GB RAM, NVIDIA GeForce 9800 GT
Endangered City. An Endangered Species
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 17th Mar 2011 15:32
Good job on getting the collision working. Normally, if a space ship collides with anything (especially a planet), the ship would explode. Typically, a float variable is used for an object's speed. If this were the case with your code, the ship would continually crash back into the planet, so it would not work. I would suggest you code it so that the ship explodes and a 'life' is lost.

I would suggest if the player's ship is shot by an alien ship or perhaps is hit by a small asteroid/space junk/whatev, that you could reduce the shield strength.

I didn't see where you could actually move the player's ship around in the code you have posted.

Thistle Studios
17
Years of Service
User Offline
Joined: 1st Mar 2007
Location: Kirkcaldy
Posted: 17th Mar 2011 19:13
The idea behind my game is when you fly within a specific distance to a planet, it initiates a cutscene where you land on the planet, adding to the other elements that I hope to implement.

Intel Core i5 3.2 GHz, 4 GB RAM, NVIDIA GeForce 9800 GT
Endangered City. An Endangered Species
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 17th Mar 2011 20:20
Okay, do you have everything working the way you want it so far?

Another way you might go about this would be to check the distance from the player's ship to each planet. There are a few ways to do that; I use vector3. To use vector3, put the following code

near the beginning of your code.
I use the following function:
. It is called from within the code like this

Bear in mind that you would have to list actual object numbers/variables in the call, and would not be able to list 0, as it will error.

Thistle Studios
17
Years of Service
User Offline
Joined: 1st Mar 2007
Location: Kirkcaldy
Posted: 17th Mar 2011 21:05
I'm having a new problem.
The variables that I define (Hull, Shield) do not get changed in the code at all. I set them at the beginning as Hull = 100, Shield = 100 but in the functions I use DEC Hull, 5 but nothing happens when I collide with the planet. I have tried IN/OUT parameter passing but that didn't work either.

Intel Core i5 3.2 GHz, 4 GB RAM, NVIDIA GeForce 9800 GT
Endangered City. An Endangered Species
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 18th Mar 2011 01:39
Try setting up the variables as global variables. If you are using them in a function they must be declared as global near the start of your code. All variables in functions are local unless declared as global.

On a side note, variables used in a subroutine are not local.

Login to post a reply

Server time is: 2024-09-29 02:39:14
Your offset time is: 2024-09-29 02:39:14