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 / DBC --> Collision

Author
Message
Ginga
18
Years of Service
User Offline
Joined: 3rd Jul 2006
Location: Dorset, England
Posted: 15th Jul 2006 14:56
ok.. this is mighty frustrating, decided to make a (not-so)simple Pong game, but alas something that should be simple is not. Started off with the camera hovering above the scene, with 2 cubes either end and a lovely sphere in the middle.

I told the program to make the ball go ---> that way ---> (right) at the start of the main do/loop

It did what it was told to (aww the good lil thing)

The Whoops! forgot about collision, So i hastily Added it, and after a few trial and errors and looking at the Help's Example i manged to get collision working between the sphere and the first cube (on the right). I even managed to get it to bounce the other way (by using yrotate ob,270) and to even play a lovely little sound.

All was going well, so i copied the same code and changed the numbers for the second cube(the one you control) but, no matter what combinations i can think of, it just goes striaght through the damn thing! and YES i do have global collisions on. Heres the code if anyone would like to point me in the right direction.



ovvy, if you wanna use the code, feel free to take the sound out.
Ginga
18
Years of Service
User Offline
Joined: 3rd Jul 2006
Location: Dorset, England
Posted: 15th Jul 2006 15:10
ok...strangeness .. i changed one number and it worked :S how damn strange

Previous


Now


change was
if object collision(3,2)>0 --> if object collision(3,0)>0

i really dont understand it, but hey if it works i aint complaining
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 15th Jul 2006 23:02
The ROTATE OBJECT command doesn't rotate the object based on it's current rotation, it rotates it to the angle you specify based on it's starting rotation. So using rotate object 3,270 would rotate it 270 degrees from where it started when the game started, regardless of it's angle. That's why it went through the paddle. You can fix this by adding the object's current angle to the rotation;

yrotate object 3,object angle y(3)+270

However using this method, eventually the object's angle could go above 360, which can make things difficult later on when you need a rotation value between 0 and 360. This is where wrapvalue comes in, it'll find out what number between 0 and 360 a given number should be. So if you gave wrapvalue the value -90, it would return 270. If you gave it 720, it'd give you 360, etc. Changing the above code to;

yrotate object 3,wrapvalue(object angle y(3)+270)

The reason yours (kind of) works now is because you're rotationg object 3 to 90 degrees when it hits the left paddle. This means it'll go straight down.

The object collision command accepts 1 object as the second parameter, or 0. If you put 0, it checks for collision with every object in the program. Here's the code fixed;



(Untested but Im pretty sure that'll work). There's no need for the second collision check now.


Projects: Online CTF Game | Newcommer's Guide to FPS's
Ginga
18
Years of Service
User Offline
Joined: 3rd Jul 2006
Location: Dorset, England
Posted: 16th Jul 2006 00:00
havnt had time to test it yet, but if it does work, then DUDE your a life saver!

Login to post a reply

Server time is: 2024-09-25 03:38:53
Your offset time is: 2024-09-25 03:38:53