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 / how to know if object is touching another object?

Author
Message
David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 8th Sep 2007 17:42
hi,how can i tell if a particular object is touching any other object???

anyone have a code snippet for this??
Penfold
20
Years of Service
User Offline
Joined: 3rd Dec 2003
Location: RED postbox houses of parliment
Posted: 8th Sep 2007 18:07
put *collision* in the search box. If it's sprites put *sprite collision* in the search box.

I've noticed you've been on here a while, I'm sure you know how to do a search.

Even better still find TDk's tutorials and put the page in your favourites. He has an exstensive tutorial on collision of all types.

I'd start there

'Ooh 'eck chief'...'crumbs'
dark donkey
18
Years of Service
User Offline
Joined: 4th May 2006
Location:
Posted: 8th Sep 2007 20:58
Okay sorry forr hyjaking your thread but i thought it would be better than starting a new one. Ive made a cupple of programs(Some good, some crap) Bt know i was just writing some code when i run it to my suprise the ONJECT HIT (1,0) Doest work. Why my source is
Collision system(Not very good)


Full code:



Thanks Dark Donkey_
vorconan
17
Years of Service
User Offline
Joined: 4th Nov 2006
Location: Wales
Posted: 8th Sep 2007 23:59
Just use dark physics



dark donkey
18
Years of Service
User Offline
Joined: 4th May 2006
Location:
Posted: 9th Sep 2007 01:17
Hmm helpfull. And what if i dont have dark Physics?.
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 9th Sep 2007 01:58
@dark donkey - OBJECT HIT only tells you the first time an object touches another, and then will return 0 the rest of the time the objects touch. OBJECT COLLISION tells you when objects are overlapping. I also doubt that locked objects will work with the collision commands because of the weird way they work.

Boo!
vorconan
17
Years of Service
User Offline
Joined: 4th Nov 2006
Location: Wales
Posted: 9th Sep 2007 02:41
Quote: "Hmm helpfull. And what if i dont have dark Physics?."


Sorry, I was answering David, but you can use Sparky's collision or Newton still



pcRaider
17
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 9th Sep 2007 02:51 Edited at: 9th Sep 2007 06:51
This improved a program of TDK.
This may help you.





dark donkey
There is a mistake in your program.
An object does not move.
I explain it on the next day.
David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 9th Sep 2007 03:29
what im trying to do is make alot of trees rocks etc,but if they are touching each other i want to delete it or have it moved until none of them touch.
dark donkey
18
Years of Service
User Offline
Joined: 4th May 2006
Location:
Posted: 9th Sep 2007 12:37 Edited at: 9th Sep 2007 14:06
Quote: "dark donkey
There is a mistake in your program.
An object does not move.
I explain it on the next day. "


There is if you look in the source i have used control camera using arrowkeys and lock object on. Well this is moving the object isnt it?.

[EDIT]:

Quote: "I also doubt that locked objects will work with the collision commands because of the weird way they work"


How else am i ment to sort of lock the obejct on the screen?. If i make basic movment when i rotate the camera i would roate the object but this wouldent work.
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 9th Sep 2007 16:25 Edited at: 9th Sep 2007 16:28
This command will say if they are touching or not: OBJECT COLLISION( First Object, Second Object ). If both the first object and the second object are colliding with each other, this command returns a 1. If not, then it returns a 0. If you change the Second Object Number to 0, then it will check if the First Object is colliding with ANY object, not just the second object that you might have put in there. If it is, then it will return the object number of the object that it's colliding with. If not, then it returns a 0.

When two objects are touching each other, it's called a COLLISION.

Example:



dark donkey
18
Years of Service
User Offline
Joined: 4th May 2006
Location:
Posted: 9th Sep 2007 17:02
WoW Sixty Squares. That was really helpfull. I get it now. But say if i have used the command "Lock Object On ObjectNum" To lock a gun to the screen. then will the "Object Collision" Work?. Thanks for any help. I plan to make a long shpere and put it infront of the gun so thats were the bullit would be hide it and then if the mouse is pressed detect if anythnig is coliding and if it is play the die anim and delete object.

Thanks
Dark Dony_
Penfold
20
Years of Service
User Offline
Joined: 3rd Dec 2003
Location: RED postbox houses of parliment
Posted: 9th Sep 2007 17:18 Edited at: 9th Sep 2007 17:18
Quote: "what im trying to do is make alot of trees rocks etc,but if they are touching each other i want to delete it or have it moved until none of them touch. "


Personally and everybody else will prolly disagree I'd get a bit of plotting paper and work out exactly where they need to go then either stick that in a readable data statement or instance each tree and position individually.

Unless you want completely random... then you'll need to something like like the object check for collision with all the other objects , then delete or randomly plot again. this however will probably take a lot of system resources up though. I would get some graph/ plotting paper and use specific co-ords (basically the same way a level creater works). and you can re-use and create new areas.

<edit> or what the heck create a simple level maker.

'Ooh 'eck chief'...'crumbs'
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 9th Sep 2007 17:23 Edited at: 9th Sep 2007 17:23
@Dark Donkey:

I've never really tried making an FPS before, but what I would do is make an invisible (HIDE OBJECT) sphere or something and position it wherever the camera is each loop. Then, just check for collision against that sphere. I'd think of the gun as more of a decoration than a collision detector, and leave the collision up to the invisible sphere.

To answer your question, I do not think OBJECT COLLISION works on objects that are locked onto the screen.

dark donkey
18
Years of Service
User Offline
Joined: 4th May 2006
Location:
Posted: 9th Sep 2007 17:31
Quote: "To answer your question, I do not think OBJECT COLLISION works on objects that are locked onto the screen."


Thansk for the fgast replie. But it i placxe the gun in the exact same place as teh camera and rotate both at the same tiem will it have the same affect?. Thanks for all the help i understand now. But i also have another idea. The lock object command wont work. But if i position it it will detect collision. So just after the collision detection in the loop if i get the object position and position it there it will be in the same place and it mgith work. I hope .

Anyway SixtSquares that is a big help thanks.
David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 9th Sep 2007 23:44
thanks sixty,thats a good example!

i think i know how to code it now,i want my trees etc randomly placed.just not inside a house or something.thanks for the help!!




----my ugly broinlaw lol haha
pcRaider
17
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 10th Sep 2007 05:42 Edited at: 10th Sep 2007 05:45
dark donkey
I think that it is understood with this cord.


debug1 (An object1 does not move.)


debug2


if TPS_view then
dark donkey
18
Years of Service
User Offline
Joined: 4th May 2006
Location:
Posted: 10th Sep 2007 23:39
PCraider, Thanks. But i dont have time to test it and that now. But i wil do first thing when i get on tommorow. Just have to ask bout some code:

Quote: " IF KEYSTATE(17)=1 THEN MOVE OBJECT 1, 0.1
IF KEYSTATE(31)=1 THEN MOVE OBJECT 1,-0.1
IF KEYSTATE(30)=1 THEN MOVE OBJECT LEFT 1, 0.1
IF KEYSTATE(32)=1 THEN MOVE OBJECT RIGHT 1, 0.1
"


I dont really get it. I think it will just move the boject to were it should be. But im not sure. And im guessing key state's are key presses(Sorry im used to using skancodes).

Thanks,
Dark Donkey_
pcRaider
17
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 11th Sep 2007 07:55
Would the collision be understood?


Quote: "IF KEYSTATE(17)=1 THEN MOVE OBJECT 1, 0.1 "

If a keyboard was pushed, this moves object 1.

In Scancode,You put a number corresponding to a keyboard.
http://forum.thegamecreators.com/?m=forum_view&t=46311&b=1
dark donkey
18
Years of Service
User Offline
Joined: 4th May 2006
Location:
Posted: 11th Sep 2007 11:18
Quote: "Would the collision be understood?"


Yes thanks for that. You have been a big help.

For the keystate, i think i get that. Thanks alot pcRaider you have helped me aload.

Thanks,
Dark Donkey_

Login to post a reply

Server time is: 2024-09-27 05:16:44
Your offset time is: 2024-09-27 05:16:44