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 / Sphere-like collision?

Author
Message
CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 17th Aug 2010 09:00
No media required for code testing
DBpro 7.4-7.5
Windows Vista

Test out my code and as you can see the sphere is jumping around (because this was originally made for a cube) how would I edit it to make it more sphere like and proper using this type of collision?
I really don't want to try something else right now because I have an idea for a game in my head where you don't really need good collision since the map is probally gonna be made out of cubes and boxes.

[THE CODE]

[/End of THE CODE]

I want coke, not Pepsi!
Grumpy Jedi
16
Years of Service
User Offline
Joined: 16th Jan 2010
Location:
Posted: 17th Aug 2010 09:38 Edited at: 17th Aug 2010 09:42
Give this a shot Cola...

I moved your camera updates after all movement commands, then added object position checks for your sphere with float values for precision.




Good Luck with your game.


EDIT: oops almost forgot I added some code into your collision checks that just keeps the sphere in place instead of moving it upward if a collision occurs, should keep it smooth instead of jumpy.

I remmed out your original lines but left them in place.
CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 17th Aug 2010 20:05 Edited at: 17th Aug 2010 20:08
That's great except when you start push up till you hit the cube then hit spacebar and the sphere will get stuck half way, I also raised the gravity, it was a bit low


Also I was tring to get the camera to view the sphere from the side instead of the back, so I could see the collision from a different angle and I didn't get much luck with that.
How would I make it so the WASD keys move the camera around the sphere?
W-up
S-Down
D-Left
A-Right

I want coke, not Pepsi!
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 17th Aug 2010 20:27
You could rotate the camera with the mouse:

You will need globals
CameraDistance#
CameraX#,CameraY#, and CameraZ# . You can replace these with your ball's x,y,z
AngleX# and AngleY#

This will give you an orbit that you can adjust with the mouse movement and distance from your ball with the scroll of the mouse.

The fastest code is the code never written.
CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 17th Aug 2010 21:02 Edited at: 17th Aug 2010 21:04
I don't really want to be able to rotate with the mouse, just the wasd for the player.
Also do you know whats wrong with the collision?
I'm thinking of getting the dark bonanza for dark physics and other stuff.
Mainly dark physics for the perfect collision in very little code.

I want coke, not Pepsi!
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 17th Aug 2010 21:19
Why do you not want to use the mouse?

In your "down" collision detection, this does nothing:
position object 1,x,y,z

Not to mention, if you are using a sphere as your "player", you don't need the four-corners approach. You only need to check what is directly below the center of the ball.

....instead of checking the 4 sides.....
The side collisions should work fine.

The fastest code is the code never written.
CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 17th Aug 2010 22:06
but don't I need up, down, left, and right collision? ground, air, left, and right? I need it for my game.
Also what do you mean in my down collision detection? You wrote it

And I would just prefer to use wasd instead of the mouse.

Also is dark physics the best approach for collision and gravity?

I want coke, not Pepsi!
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 17th Aug 2010 22:16
Quote: "Also is dark physics the best approach for collision and gravity?"

It depends on the type of game. What I have seen of your game, you don't need anything but the built-in collision system.

As far as the collisions you need, I think you only need Down, Right, Left, Forward, and Back. Correct me if I'm wrong, your game is simply this:
A ball that moves along a series of boxes that make the ground and some barriers. Gravity pulls the ball down and the player tries to keep the ball on the boxes... Right?

The fastest code is the code never written.
CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 17th Aug 2010 22:25
Quote: "As far as the collisions you need, I think you only need Down, Right, Left, Forward, and Back. Correct me if I'm wrong, your game is simply this:
A ball that moves along a series of boxes that make the ground and some barriers. Gravity pulls the ball down and the player tries to keep the ball on the boxes... Right?"


Yes but I also will maybe be using roofs sometimes for more obstacles so I need Up too, but with the code I have right now when I jump right beside a wall I get stuck to it, and I also still need the WASD camera movement

I want coke, not Pepsi!
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 17th Aug 2010 22:32
You get stuck to it? Or the ball gets stuck IN it? Does the ball go into the wall more than half way when it is "stuck"?

The fastest code is the code never written.
CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 17th Aug 2010 22:47 Edited at: 17th Aug 2010 23:14
Quote: "You get stuck to it? Or the ball gets stuck IN it? Does the ball go into the wall more than half way when it is "stuck"?"


Test it out, and I can't tell because I cant turn the camera very good (im no good with cameras :s)

I want coke, not Pepsi!
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 18th Aug 2010 01:57

Don't fight the mouse movement! Right-click and drag to move the camera. Use the scroll to zoom in and out. For overhead collisions, I want it to be a test of your abilities. Look at the "down" collision and adapt it so you will test "up" collision.

The fastest code is the code never written.
CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 18th Aug 2010 02:05
Quote: "Don't fight the mouse movement! Right-click and drag to move the camera. Use the scroll to zoom in and out. For overhead collisions, I want it to be a test of your abilities. Look at the "down" collision and adapt it so you will test "up" collision."


Hm, with that camera code it doesn't follow the sphere... I keep having to right click for it to go to the sphere, and the collision code is ok, its mostly working, i'm gonna see if I can get dgs bonanza.
Do they mail/ship it to you or email it or what?

I want coke, not Pepsi!
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 18th Aug 2010 02:21

Fixed.

All the fancy packages in the world will do nothing if you don't know how to impliment them. Stick with this until you understand it. This code is more than sufficient for the type of game you are making. If you get into something else without understanding the basics, you will get lost and have to ask for more help on a completely new issue.

What we are doing is the BASICS of collision and physics.

The fastest code is the code never written.
CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 18th Aug 2010 02:25 Edited at: 18th Aug 2010 02:30
Quote: "All the fancy packages in the world will do nothing if you don't know how to impliment them. Stick with this until you understand it. This code is more than sufficient for the type of game you are making. If you get into something else without understanding the basics, you will get lost and have to ask for more help on a completely new issue.

What we are doing is the BASICS of collision and physics.
"


I know that but it seems like dark physics is so much simpler.
Do you know how they send the bonanza to you?

Also how do you edit it so it's like even if theres the littlest part on the sphere will stay on?

I think I added top collision and also here is the code:


All so how do I make the cube go the way the camera is looking??

I want coke, not Pepsi!
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 18th Aug 2010 02:37
Quote: "All so how do I make the cube go the way the camera is looking??"

Did you mean "sphere"? You can point the object (sphere) in the same direction as the camera. That also means you will have to change the way you do the movement.
You did fine figuring out how to do the "up" collision. So, here's the next step. Look up "YROTATE OBJECT" and "camera angle y". See if you can figure out how to make the object point in the same direction as the camera....

The fastest code is the code never written.
CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 18th Aug 2010 02:58
Quote: "Quote: "All so how do I make the cube go the way the camera is looking??"
Did you mean "sphere"? You can point the object (sphere) in the same direction as the camera. That also means you will have to change the way you do the movement.
You did fine figuring out how to do the "up" collision. So, here's the next step. Look up "YROTATE OBJECT" and "camera angle y". See if you can figure out how to make the object point in the same direction as the camera...."

Will the collision work the same with the yrotate thing?

I want coke, not Pepsi!
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 18th Aug 2010 03:07
Yes. Unless you have oddly rotated blocks, the collisions we set up will work fine. Let me know what you come up with. Remember, you will have to change the way you do movements.

Sometimes trial and error is the best way to learn.

The fastest code is the code never written.
CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 18th Aug 2010 03:10
Quote: "Yes. Unless you have oddly rotated blocks, the collisions we set up will work fine. Let me know what you come up with. Remember, you will have to change the way you do movements.

Sometimes trial and error is the best way to learn"
.

I might just hold out till (or if) I get physics. I know i could do this but I will know for sure if i'm getting it tomorrow probally.

Where do you go to ask questions about how to send it to you or stuff?

I want coke, not Pepsi!
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 18th Aug 2010 03:29
I have never had to buy anything. What you are wanting CAN be done with the built-in DBP collisions. You have been working on this same game for at least a month. I'm trying to help you UNDERSTAND how to do collisions. Adding more commands will not make it more clear. You have to learn the basics. I will give you one last thing:

This code has a lot of stuff you can learn from. Play with it. Break it. Then fix it. Disect each line. See what makes it tick. Trial and error is one of your greatest allys.

The fastest code is the code never written.
CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 18th Aug 2010 03:51 Edited at: 18th Aug 2010 05:48
Quote: "I have never had to buy anything. What you are wanting CAN be done with the built-in DBP collisions. You have been working on this same game for at least a month. I'm trying to help you UNDERSTAND how to do collisions. Adding more commands will not make it more clear. You have to learn the basics. I will give you one last thing:
+ Code Snippet

sync on
sync rate 60
Make object sphere 1,20
position object 1,0,0,0
point object 1,0,0,100
make object cube 2,20
position object 2,0,0,40
make object cube 3,20
position object 3,20,0,40
make object cube 4,20
position object 4,-20,0,40
make object cube 5,20
position object 5,0,20,40
make object cube 6,20
position object 6,0,-20,0
make object cube 7,20
position object 7,0,-20,20
make object cube 8,20
position object 8,0,-20,40
make camera 1
global CameraDistance# as float
CameraDistance#=20.0
global AngleX# as float
global AngleY# as float
RotateCamera()
do
RotateCamera()
rem gravity
move object down 1,Falling#
inc Falling#,0.1

rem positions
x=object position x(1)
y=object position y(1)
z=object position z(1)
rem collision
for b=2 to 8
D#=INTERSECT OBJECT(b,x,y,z,x,y-10.0,z) `this tests the "Ground Mesh" for a collision (or ray intersection)
if D#<=10.0 and D#>0.0
move object up 1,(10.0-D#)
Falling#=0
Endif
D#=INTERSECT OBJECT(b,x,y,z,x,y+10.0,z) `this tests the "Ground Mesh" for a collision (or ray intersection)
if D#<=10.0 and D#>0.0
move object down 1,(10.0-D#)
Falling#=0
Endif
Next b
rem movement and jumping
remstart
if upkey()=1 then position object 1,x,y,z+1
if downkey()=1 then position object 1,x,y,z-1
if rightkey()=1 then position object 1,x+1,y,z
if leftkey()=1 then position object 1,x-1,y,z
remend
if upkey()=1
move object 1,1
endif
if downkey()=1
move object 1,-1
endif
if leftkey()=1
move object left 1,1
endif
if rightkey()=1
move object right 1,1
endif
if spacekey()=1 and Falling#=0.0
move object up 1,1
Falling#=-3.0
endif
rem new positions
x2=object position x(1)
y2=object position y(1)
z2=object position z(1)
rem side-side collision

for b=2 to 8
D#=INTERSECT OBJECT(b,x2,y2,z2,x2-10.0,y2,z2)
if D#<10.0 and D#>0.0
position object 1,x2+(10.0-D#),y2,z2
Endif
D#=INTERSECT OBJECT(b,x2,y2,z2,x2+10.0,y2,z2)
if D#<10.0 and D#>0.0
position object 1,x2-(10.0-D#),y2,z2
Endif
D#=INTERSECT OBJECT(b,x2,y2,z2,x2,y2,z2-10.0)
if D#<=10.0 and D#>0.0
position object 1,x2,y2,z2+(10.0-D#)
Endif
D#=INTERSECT OBJECT(b,x2,y2,z2,x2,y2,z2+10.0)
if D#<=10.0 and D#>0.0
position object 1,x2,y2,z2-(10.0-D#)
Endif
Next b

sync
loop

function RotateCamera()
MX# as float
MX#=MOUSEMOVEX()
MY# as float
MY#=MOUSEMOVEY()
if mouseclick()=2
AngleY#=AngleY#+(MX#/5.0)
AngleX#=AngleX#+(MY#/5.0)
endif
if AngleX#>70.0 then AngleX#=70.0
if AngleX#<-70.0 then AngleX#=-70.0
MouseScroll#=mousemovez()/10.0
CameraDistance#=CameraDistance#-MouseScroll#
if CameraDistance#>1000.0 then CameraDistance#=1000.0
if CameraDistance#<10.0 then CameraDistance#=10.0
position camera 1,object position x(1),object position y(1),object position z(1) `the lookat point
rotate camera 1,AngleX#,AngleY#,0.0
yrotate object 1,camera angle y(1)
move camera 1,-CameraDistance#
endfunction


This code has a lot of stuff you can learn from. Play with it. Break it. Then fix it. Disect each line. See what makes it tick. Trial and error is one of your greatest allys."


Ok, and I havent been working on it for a month, about 2-3 days

Also thanks for the code but when you go ontop of the highest block ur bouncing, I'll try to fix it

I want coke, not Pepsi!
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 18th Aug 2010 15:42
Quote: "Ok, and I havent been working on it for a month, about 2-3 days "

Seriously???? So this thread is not you? Started 24Jul10 and I was a major contributor to it. http://forum.thegamecreators.com/?m=forum_view&t=173143&b=1

Quote: "when you go ontop of the highest block ur bouncing"

I noticed that only when I hit the edge of the block.... I didn't see it any other time. I'm at work now, so I can't compile it myself and see, so you'll have to troubleshoot that part on your own. I have confidence that you can do it. Let me know how it comes out.

The fastest code is the code never written.
CocaCola
16
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 18th Aug 2010 19:08
Quote: "Seriously???? So this thread is not you? Started 24Jul10 and I was a major contributor to it. http://forum.thegamecreators.com/?m=forum_view&t=173143&b=1"


No, no you were a HUGE help. I was just trying to learn basic collision and gravity I wasn't working towards a game really, now I am. Back then I was just trying to learn some stuff before I even started a game.
Thanks so much for that by the way, your definately the biggest help i've had on here.

I want coke, not Pepsi!

Login to post a reply

Server time is: 2026-07-24 20:36:01
Your offset time is: 2026-07-24 20:36:01