We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm trying to have 2 rectangles which can collide each other. I have something that seems good to me but when the first one goes on the second, the image can go through the second but nothing happend until the middle of the image. I thought it was a problem with my coords but they are accurate so i'm pretty lost now.
Here you can take a look on this sample of my project : http://paste2.org/w4G3etCZ
Have a good day :)
Answers
Google rectangle collision detection or
collision detection
In the forum or the web
It has been done
Iirc the idea is to check if they overlap and then just take the opposite
Using not which is !
I already followed this, my formula comes from there
your collision detection depends on the image mode you are using. you saying this makes me think you are using one image mode but the collision detection (which looks ok for CORNER mode) is coded for another.
https://processing.org/reference/imageMode_.html
we need the whole of your code to fix it. posting tiny samples seems to have become a thing here recently. and it really doesn't help us. runnable examples make things much easier.
Ok i'll watch, but my co is a bit long and not everything is usefull so shall I give you the whole thing ?
Post the entire Code here
[Link removed due to phishing warnings]
Firefox is giving me this warning
This web page at paf.im has been reported as a deceptive site and has been blocked based on your security preferences.
Just post the code
I have the same thing but no problem on it.
It's too big and I have files and many tabs
try and write a smaller example featuring just the bits that are wrong and post that.
actually, here's a start using rectangles
NOTE the rectMode(CENTER);
it shows something similar to what you describe. change it to rectMode(CORNER) and it's fine (but the rectangles are offset a bit - the mouse pointer is now top left of the moving rectangle, not in the centre)
@koogs doesn't work try moving mouse from bottom right corner.Ignore this my mistake.The collision method in the original code depends on whether the [x,y] coordinates represent the centres or the top-left corners of the rectangles.
It would be better to have a generic box-box collision functions where the appropriate rectangle coordinates are passed as attributes.
i know it doesn't work:
ie the bug. gotta reproduce it before you fix it!
this was my attempt at a small example to get over the 'It's too big and I have files and many tabs' excuse
This demonstrates what I mean. It has a single method to detect collision between two rectangles. The parameters represent the top-left and bottom-right corners of the rectangle, as long as the values passed to the function represent these values it doesn't matter how you store the actual reactangle data.