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 / i need help with collision detection

Author
Message
stupid kid
20
Years of Service
User Offline
Joined: 16th Sep 2004
Location: at my house
Posted: 15th Dec 2004 11:14 Edited at: 15th Dec 2004 11:15
I am making a simple racing game in Dark Basic Classic. In the game you are a penguin and you are racing against a snowman. I am trying to find out how to make it so that when you hit the walls, the snowman, or the trees you stop instead of going threw them. I would also like to know how to make my snowman and my penguin face in the correct directions.



the ai blocks are invisible blocks that later on i am going to make the snowman rotate when he hits them so that the snowman can turn around the corners.

Please help me with collision detection so that i can make this game become more like a game.
stupid kid
20
Years of Service
User Offline
Joined: 16th Sep 2004
Location: at my house
Posted: 16th Dec 2004 05:08 Edited at: 17th Dec 2004 10:15
I changed the program so that the trees look more like trees and i also tried to figure the collision detection myself and this time i think it got it right but i am in the middle of the screen and i can't move now.
I think that darkbasic thinks that the penguin is colliding with the floor which is a box, but i dont understand why that is because i shut off collision detection for the floor. the floor is object 4, i think.



all the media is on the darkbasic cd
Can somebody please help me

edit: I fixed the problem with getting stuck in the middle, all the collision detection works now except for the trees, i tried to make a collision box around the trees but that didn't work, i've been trying to figure out how to fix this for a long time but i don't understand collision detection. This is my new code


can somebody please explain how to do collision detection, i looked in the help files but there's no information that helped me.

edit: SInce the tree isn't detecting collision could i put a box around it and then hide the box ang get the collision detection from the box like

make object cube 500,50
load object "tree2.x",10
SCALE OBJECT 10, 5000, 5000, 5000
position object 10,0,25,600
position object 500,0,25,600
hide object 500

i haven't tried that but would it work?

edit: The invisible boxes around the trees worked but making a box to go around every tree and positioning them in the right spots took alot of typing if there is a easier way please tell me
Dom
20
Years of Service
User Offline
Joined: 31st May 2004
Location:
Posted: 17th Dec 2004 18:32
Ha looks like me and you have got the same AI ideas
Quote: "the ai blocks are invisible blocks that later on i am going to make the snowman rotate when he hits them so that the snowman can turn around the corners. "
My AI System does that plus lots lots more!

DRAGONFIRE STUDIOS
Lead Programmer
(The Studio being my front room)
stupid kid
20
Years of Service
User Offline
Joined: 16th Sep 2004
Location: at my house
Posted: 18th Dec 2004 01:23 Edited at: 18th Dec 2004 01:24
i figured out the problem with the trees but i am having trouble with the ai now.

the snowman goes foward hits the first ai block
then goes backwards and walks right through the first on and leaves the level, i don't understand why it is doing this because when the snow man collides with the blocks he is supposed to rotae 90 degrees not 180 and he is supposed to rotae 90 degrees when he hits the first block to, to help u understand i drew a picture of what the snowman is doing. the blocks are invisble blocks that are supposed to make the snowman rotate, the circle is the snowman and everyting else is the level.



the code for my game


please help me with the snowmans ai, i want him to go around the racetrack
Dom
20
Years of Service
User Offline
Joined: 31st May 2004
Location:
Posted: 18th Dec 2004 05:15 Edited at: 18th Dec 2004 05:16
You know there is an easier way of loading all those trees just do:

For X = 1 to 22
Load Object "Tree.x",X
Scale Object X,5000,5000,5000
Position Object X,RND(600),25,RND(625)
Next X

As for the AI
rem snowman a.i.
if object collision(3,500) then yrotate object 3,90
if object collision(3,501) then yrotate object 3,180
if object collision(3,502) then yrotate object 3,270
if object collision(3,503) then yrotate object 3,360
move object 3, 8

Try that

DRAGONFIRE STUDIOS
Lead Programmer
(The Studio being my front room)
Dodo
20
Years of Service
User Offline
Joined: 8th Aug 2004
Location: eating lunch
Posted: 18th Dec 2004 05:26
the reason your snowman is doing this is because when you use this code:



DB rotates the object so that it is facing 90 degrees, so it will always face left(on your diagram) when you call this.

What you want to do is add 90 degrees to the current snowman angle, so to do this you need to use object angle y(ObjNo) and wrapvalue(). object angle y gets the objects y angle, and wrapvalue keeps the number within 360 degrees, and wraps it round if it goes over 360 or under 0.

using these commands, your new ai code should look like this:



hope this helps.

Part of solving the problem is actually noticing that the problem is there in the first place

stupid kid
20
Years of Service
User Offline
Joined: 16th Sep 2004
Location: at my house
Posted: 18th Dec 2004 05:33
i am trying your ideas for the snowmans ai right now

and the reason i didn't randomly position the trees was because i needed them on the race track they couldn't be on any of the walls or where the player starts or anything and since the collision detection for the trees were messed up i needed to create the cubes and position them in the exact spot that the trees are in
Stevil
22
Years of Service
User Offline
Joined: 31st Oct 2002
Location: Australia
Posted: 18th Dec 2004 06:24
collision is very tricky, all depends exactly you want it to do, if you want them to slide along the wall or if you want them to bounce of the wall or etc, MANY options to pick from, please tell us exactly what you want to happen when you hit a wall.

Quote: "the ai blocks are invisible blocks that later on i am going to make the snowman rotate when he hits them so that the snowman can turn around the corners"


A better way to do this is not use objects, uses less memory an CPU power if you just check the positions. You can even store it all in an array to make things easier



This isn't the best way to do things, but its 9:30 sunday morning an I'm not in a coding mood cause someone woke me up.
stupid kid
20
Years of Service
User Offline
Joined: 16th Sep 2004
Location: at my house
Posted: 18th Dec 2004 06:30 Edited at: 18th Dec 2004 06:30
i got the ai working
the correct code was
if object collision(3,500) then yrotate object 3,270
if object collision(3,501) then yrotate object 3,90
if object collision(3,502) then yrotate object 3,360
if object collision(3,503) then yrotate object 3,180

stevil, i do not understand your code and since i'm a just learning dark basic i am going to do it the easy way.

thanks everyone for helping me
Stevil
22
Years of Service
User Offline
Joined: 31st Oct 2002
Location: Australia
Posted: 18th Dec 2004 06:42
Quote: "stevil, i do not understand your code and since i'm a just learning dark basic i am going to do it the easy way."


This is fair enough If you do not understand it because of the arrays I suggest you learn them A.S.A.P will makie life alot easier for you. There was a pretty good example in the DB help in the old days, I can only assume its still there. Its a lotto example of sorts where it picks numbers an stores them.
stupid kid
20
Years of Service
User Offline
Joined: 16th Sep 2004
Location: at my house
Posted: 18th Dec 2004 10:44 Edited at: 18th Dec 2004 10:45
i do not understand arrays but i will look them up in the help files later

the ai is working great now but i have another problem
I want it so that when you go around the race track 3 times and u got around faster than the opponet i want it to say you won and then bring you to the next race track after i make another race track. To do this i made a box, textured it and that box is my finish line, i want it so that when you collide into it it adds to your laps variable but if you just stand in there it keeps adding and adding to that variable, can u please help me to fix this problem.



also how do u make levels or race tracks that aren't so square, I want some race tracks that are curved or in other shapes that i can't acheive using boxes and making all those boxes and placing them in the right spot is difficult

pleas help me
demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 18th Dec 2004 16:44
Have a variable (e.g. "linecrossed#") and if it equals 1 then when you hit the line it won't increase the laps, and if it equals 0 then when you hit the line it increases. Then halfway through the course have another box that sets linecrossed# to 0.

Am I the only one here who's really confused?
stupid kid
20
Years of Service
User Offline
Joined: 16th Sep 2004
Location: at my house
Posted: 19th Dec 2004 01:19 Edited at: 19th Dec 2004 03:59
i tried what u said demonsbreath but i get a syntax error. unrecognized parameter at line 240. I dont understand y I am getting this error because i think i typed everything in correctly.

Line 240 says
if object collision(2,300)>0 and linecrossed#=1 then laps#=laps#+1 linecrossed#=0

an my whole program says


can someone also tell me how to make levels without them being made out of boxes, and how to place thing in the levels more easier

i want to make a race track like this

the blue is the ice thats the race track
the white is snow, the player can't go on the snow and the green spots is trees, how would i make this into a level

edit: I figured out the error, i changed the code to this
if object collision(2,300)>0 and linecrossed# = 1
laps#=laps#+1
linecrossed#=0
endif
if object collision(3,300)>0 and enemylinecrossed#=1
enemylaps# = enemylaps#+1
enemylinecrossed#=0
endif

But i still would like to know how to make other race tracks

edit: i have another problem after you complete 3 laps and you done it faster than the opponet, you are supposed to get a white screen with the words you won in the center of the screen, after i complete 3 laps the screen just freezes instead, here is some of my code
this code is at the end of the program

rem check to see if you won
if laps#=3 and laps# > enemylaps# then gosub youwon
if laps#=3 and laps# < enemylaps# then gosub youlost
if laps#=3 and laps# = enemylaps# then gosub youlost

sync
loop

youwon:
cls rgb(255,255,255)
set cursor 400,320
print "You Won"
wait key
gosub menu

youlost:
cls rgb(255,255,255)
set cursor 400,320
print "You lost"
wait key
gosub menu

edit: would i use Cartography Shop to make levels like that and if i did how would i get that map in my game, is there any free programs that would work, i need help making racetracks for this game
stupid kid
20
Years of Service
User Offline
Joined: 16th Sep 2004
Location: at my house
Posted: 19th Dec 2004 22:57 Edited at: 21st Dec 2004 06:04
i really need help with the levels, i tried using matedit and magic world for creating the matrix but i dont understand matedit and magic world freezes when i click on the matrix i want to load, how can i make a racetrack like the one in the picture

edit: i made a matrix in magic world, i loaded it in but now everything is all messed up and the penguin moves messed up now and i can't figure out how i am going to make the penguin stay on the path and not go onto the snow.
here is a picture of my simple level


and here is the code i am using, i just want the penguin to be able to move on the matrix normally and not lloked messed up, i want the penguin to be on the same height as the matrix and i dont want the penguin to go on the snow


please help me

edit: the reason why the penguin moved messed up was because i forgot the sync on command and sync rate 30.

edit: i still need help with the get ground height command. It doesn't work in dbc with magic world. I trid using a function I found in a forum also but it doesn't work.



please help me

edit: get ground height works now, i had to put in a position matrix 1,0,0,0 to make it work
stupid kid
20
Years of Service
User Offline
Joined: 16th Sep 2004
Location: at my house
Posted: 21st Dec 2004 07:25 Edited at: 22nd Dec 2004 07:35
I am sorry for double posting but there is too many edits on the post above and this is a different question.

In magic world i put some object on my level. When i load the level in darkbasic the objects aren't where they are supposed to be. Why? and How do i fix that?

my code


please help me

edit: I fixed the problem by positioning the matrix to 0,0,0 in magic world instead of through code.

Attachments

Login to view attachments
Vues3d on Kalimee
20
Years of Service
User Offline
Joined: 12th May 2004
Location: NYON (SWITZERLAND)
Posted: 22nd Dec 2004 16:30
just a little improvement for the trees loading...

Your code is:


to make it faster you should:


In this case, you load ONCE the tree instead of 22 times & after that, you copy the whole scaled tree in one command.
The instance object copy the object & the properties you gave him such as transparencies, scaling & so on...
The Clone object command, just copy the object without the modification you gave to the original.

Guido
http://www.vues3d.com
bibz1st
21
Years of Service
User Offline
Joined: 2nd Jan 2003
Location:
Posted: 24th Dec 2004 20:06
in MW make sure you position the matrix at 0,0,0 first, then add your objects, otherwise you will have to get the matrix X,Y,Z and then offset the objects.
stupid kid
20
Years of Service
User Offline
Joined: 16th Sep 2004
Location: at my house
Posted: 25th Dec 2004 03:31
I fixed all my old problems with my game. The game runs great now. Almost everything works when i run it in dark basic but when i run the .exe, i get a runtime error 111.

I searched the forums but i couldn't find information on how to fix this problem. This problem has only happened since i have put music in my game.

I would also like to know how to make music for my game. I would like to know where i can find free software and tutorials on how to make music for videogames. I know that there is music maker 2005 or something sold on the darkbasic website but i want something free. I would also like to know how to make or get sound effects for my game becaus I don't like the sound effects on the darkbasic cd and i want something original for my game.

I am using darkbasic classic.
Can someone please help me.
demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 25th Dec 2004 22:30
is your .exe in the same directory as your base file?

Am I the only one here who's really confused?
stupid kid
20
Years of Service
User Offline
Joined: 16th Sep 2004
Location: at my house
Posted: 26th Dec 2004 02:31
my .exe is a final exe, so it is supposed to include all the media.
But no the final .exe is on my usb flash memory stick thing.
stupid kid
20
Years of Service
User Offline
Joined: 16th Sep 2004
Location: at my house
Posted: 31st Dec 2004 08:52 Edited at: 31st Dec 2004 08:53
I made another .exe and there is no runtime error now.

I have another problem with the ai now. I placed the objects in the world using magic world. I use the object numbers that magic world gave the objects for the collision detection in my code. I have a image of the level labeled with the objects and the numbers that magic world gave them. The one with both 5 and 6 in it is because i placed 2 objects of the same size in the exact same position and i can't figure out how to delete 1 without deleting the other. I want it so that the enemy goes around the level. Also I want it so that when the player presses the p button the game pauses but it doesn't work very well.

The enemy starts right in front of cube 4 and goes foward and goes right through cube 5 and 6.

This is my code:



Can someone please help with the ai. and I'm sorry for double posting again.

Attachments

Login to view attachments
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 31st Dec 2004 12:36
build your race track with a series of points. Draw lines from point to point then use a line check for collision. (left or right of line)

"eureka" - Archimedes
demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 31st Dec 2004 19:09 Edited at: 31st Dec 2004 19:13
First: Pause game could be done like this:



Second, this:
could become this:


It would have the same effect, but just be more efficient.

Hope I helped
demonsbreath

Am I the only one here who's really confused?
http://db1games.topcities.com
(used to be demonsbreath)
stupid kid
20
Years of Service
User Offline
Joined: 16th Sep 2004
Location: at my house
Posted: 2nd Jan 2005 12:25 Edited at: 3rd Jan 2005 04:54
I got the ai working. I deleted all the objects in magic world and placed all the objects through code.

Demons breath, thank you, i used your code in my game.

I have another problem now. I have a box that is the finish line and another box on the other side of the race track. The second box detects if the player has gone all the way around the track. The problem is that it doesn't detect that i'm colliding with these boxes and it doesnt detect the laps when i go around the race track.



please help me

------------------------------------------------

edit: I am having a new problem. The game worked, except for the collision detection on the finish line. but about 10 seconds after i typed this post and copied and pasted the source code i ran into a new problem it says unknown command at the end of line 211 which is strange because it worked right before i posted this question. I didn't change anything.

line 211 says MagicLoad("levels/racetrack1",1000,1,1000)

edit: I fixed this problem. I had a space before the magic load command and a space before the #include command. and i guess the space makes the diffrence because after i deleted the space it worked.

--------------------------------------------------

can u please help me with both of these problems.

-----------------------------------------------------
edit:

I have tried to fix the problem by replacing if object collision(200,550)>0 and enemylinecrossed#=1
with
if x#>800 and x#<850 and z#>953 and z#<1230 and linecrossed# = 1

but that doesn't work either and i dont understand why.
I have added in acceleration. It works.

I am trying to make it so that u can't climb up the walls in my level.
I want to do this without having to create invisble boxes and that stuff so i tried this

newplayery-oldplayery = heightdiffrence
if heightdiffrence < -10 then speed = 0
if heightdiffrence > 10 then speed = 0

I made it so that it checks to see the diffrence in y and if there is a big diffrence it will make it so that i can't climb up the wall. I am trying to do it this way so that i don't have to code a new collision with the wall thing with every level i make. The problem is that this doesn't work and i dont understand why it doesn't. There is a picture of my level on a post above.

I dont understand why the change in y thing and the collision with the finish line doesn't work. Can u please help me. Also i have downloaded a collision dll, i think it was called sparkys collision dll or something, the actual dll file is called DBCcollision.dll. I dont undersatnd how to use that either. I downloaded it because i thought it would help with the collision against the finish line.

my new code


please help me, i dont undersatnd why the collsion doesn't work

Login to post a reply

Server time is: 2024-11-11 22:40:32
Your offset time is: 2024-11-11 22:40:32