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 problem: getting stuck

Author
Message
Allanon Shadeslayer
17
Years of Service
User Offline
Joined: 28th Dec 2006
Location:
Posted: 23rd Feb 2007 23:56
'Lo all!

I am making a tank game and I am trying out some basic collision to keep my tank inside the boundaries i set.
But here's the problem: you get stuck if you run into something while moving forward or backward and turning at the same time.

Here is my code:


If at first you don't succeed, lower your expectations.
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 24th Feb 2007 01:25 Edited at: 24th Feb 2007 01:27
When you press a key, your code tells the object to for example move up 5. If theres a collision your code tells the object to move up and down 5, so if you work it out, it equals 0. The same for rotation, it won't rotate if theres a collision. The best way to do it is if theres a collision, position the object where that collision happen.



Also, what kind of game are you making, because your rotating in the wrong axis for going up and down. In the code, you'll notice i've changed it to the Z axis. Hope this helps.
Allanon Shadeslayer
17
Years of Service
User Offline
Joined: 28th Dec 2006
Location:
Posted: 24th Feb 2007 01:28 Edited at: 24th Feb 2007 01:38
Lol. I'm making a tank game. You can try it out. It's under Work In Progress (Titled tank arena)

I tried your code and my tank just goes right through. I want my tank to stop when there's a collision, but when I maneuver right(or wrong) my tank slowly goes inside the object I'm trying to keep it out of so it gets stuck.

You might want to try out my game to see what I mean by "Getting stuck".

Tyvm!

If at first you don't succeed, lower your expectations.
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 24th Feb 2007 02:15
Can't download it(think the problems on my end, i'll try later). Anyway, heres how I tested your code.

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 24th Feb 2007 14:50
Spherical collision?

TDK_Man

Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 24th Feb 2007 15:24
Do you mean how I position the boxes.
Allanon Shadeslayer
17
Years of Service
User Offline
Joined: 28th Dec 2006
Location:
Posted: 25th Feb 2007 22:18
Anymore help?

If at first you don't succeed, lower your expectations.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 26th Feb 2007 00:20
Check out the SET OBJECT COLLISION TO SPHERES command.

By default, DB's collision uses boxes rather than spheres.

You don't appear to be using the GET OBJECT COLLISION() functions, so you probably don't need to use spherical collision.

TDK_Man

Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 26th Feb 2007 00:20
Ok, Couldn't work out why it was happening but fixed it.

Main loop code:


It seemed changing the way they move did the trick. Also changed this:



It will still split the screen but allow you to change the screen resolution without the cameras going off the screen. Hope this helps.
DB PROgrammer
17
Years of Service
User Offline
Joined: 9th Feb 2007
Location: Nowhere But Everywhere
Posted: 26th Feb 2007 00:22
I'm not on my computer right now so I cant test it for you but try this.



Hope this works.

Working on an FPS Engine.
Allanon Shadeslayer
17
Years of Service
User Offline
Joined: 28th Dec 2006
Location:
Posted: 26th Feb 2007 22:16
Sasuke, your code stopped my tanks from slowly sliding into objects but whenever I rotate my tank to where part of it gets inside of an object I can't go out of it because it's always colliding.

Is there a way to divide my tanks into two collision zones? I think that might help a little.

If at first you don't succeed, lower your expectations.
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 26th Feb 2007 23:14 Edited at: 27th Feb 2007 13:15
I see the problem now. I think best way is to make a sphere the radius of the tank to collide with.

So, first create a collision sphere for the tank.


Then we what to move the sphere and position the tank at sphere position.


See if that helps. This is only for player 1, but shouldn't be too hard to do the same for player 2.
Allanon Shadeslayer
17
Years of Service
User Offline
Joined: 28th Dec 2006
Location:
Posted: 28th Feb 2007 02:50
Beautiful idea Sasuke!!! It worked like magic! That's exactly what I was looking for thank you very much!!!

If at first you don't succeed, lower your expectations.

Login to post a reply

Server time is: 2024-09-25 17:19:31
Your offset time is: 2024-09-25 17:19:31