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 / Delete an object if you touch it?

Author
Message
urgent help!
14
Years of Service
User Offline
Joined: 28th Sep 2010
Location:
Posted: 6th Dec 2010 20:48
I want to delete an object if my character touches it. I tried this code:

if object collision (1,550)
delete object 550
endif

with object 1 being me and 550 being the object I want gone. However, nothing happened when I touched the object. Any tips?
Eminent
14
Years of Service
User Offline
Joined: 15th Jul 2010
Location:
Posted: 7th Dec 2010 00:26
Are you sure of it's the right object? Did you put that code in the main loop?


baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Dec 2010 12:18
Yes, maybe show us a little more code? It could be that you scaled the objects up or any number of things.

Post a full example, you may find the problem preparing one!

urgent help!
14
Years of Service
User Offline
Joined: 28th Sep 2010
Location:
Posted: 7th Dec 2010 20:44
Here's a bigger sample of the code.



Objects 550-554 are switches to press, and objects 555-559 are the barriers to be deleted. However, when I touch the switches, nothing happens.
thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 7th Dec 2010 21:43

This. have you tried changing the 2 to a 1? Object 2 is never used in that code, and object 1 might not be getting set up for collision automatically.


IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th Dec 2010 14:24
You're code will also crash:


First frame, object 559 gets deleted. Next frame, you are still in collision with 554, and attempt to delete 559 again ... object does not exist.

Change it to something like this:


Also, a problem that another person had recently was to deal with general collision (walls etc) first, before checking for other collision. His problem was that the general collision moved the player out of contact with the object being collided with, meaning that the other collisions would never trigger as he was no longer colliding with anything.

urgent help!
14
Years of Service
User Offline
Joined: 28th Sep 2010
Location:
Posted: 8th Dec 2010 20:30
I have the problem mainly fixed. It seems the trouble is the size of the object; When I touch the switches, they're too big, so to really have my collision touch the box's collision, I have to mess around by sliding around the switch a bit. Any ideas?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Dec 2010 13:50
You could manually check the position of your character and check it against where the switch "zone" is...

IE:


Login to post a reply

Server time is: 2024-11-23 07:05:18
Your offset time is: 2024-11-23 07:05:18