Jump to content

Object intersection detection algorithm & Colshape troubles


JeViCo

Recommended Posts

I've recently found out that onClientColshapeHit triggers only when object's center hit the colshape

screenshot_2.jpg

screenshot_3.jpg

Functions like getElementsWithinColShape and isElementWithinColShape work on the same principle. It's kinda bad because it affects the whole gamemode i make and makes it impossible to complete. I tried to use isLineOfSightClear function however i should use it on each unit of a single object. 9x9x9 object cause performance loss so this is a bad idea. Is there any other ideas?

Link to comment
  • Moderators
On 26/06/2020 at 15:32, JeViCo said:

I've recently found out that onClientColshapeHit triggers only when object's center hit the colshape

You can multiply the colshape size by 1.5. But keep in mind that rotation values that are higher than:

(rotation % 90) > 0

Will make the calculations invalid.

 

Edited by IIYAMA
Link to comment

Thank you for reply. It works for most objects however it does not when i use narrow objects like this garage door

w1UNNmFlSNa4LDOFITFOgQ.png

I think that i can use 3-dimensional table for all axis to be 100% sure that objects are not overlapping however i should create 30003 tables to cover the whole map and that's not cool at all.

I thought I could solve my problem by using getDistanceBetweenPoints3D, but it all problems comes down to this

17 hours ago, IIYAMA said:

(rotation % 90) > 0

 

Link to comment
  • Moderators
57 minutes ago, JeViCo said:

I thought I could solve my problem by using getDistanceBetweenPoints3D, but it all problems comes down to this

You could also use this function.

https://wiki.multitheftauto.com/wiki/IsInsideColShape

https://wiki.multitheftauto.com/wiki/GetElementBoundingBox

If you run it 8x times for each corner, per object = 16x.

Then it will detect most of the collisions, except when no corners are inside each other.

There is also something by crystamv.

https://web.archive.org/web/20160507103732/http://crystalmv.net84.net/pages/scripts/server_coldata.php

But that one only supports peds and vehicles. But you could modify it to also support objects

 

 

 

 

 

Edited by IIYAMA
  • Thanks 1
Link to comment
  • Moderators
31 minutes ago, JeViCo said:

It solved my problem

But keep in mind that the solution is not bullet proof.

If the red box was 45 degrees rotated clockwise and moved a little bit higher, the collision detection would fail.

 

  • Like 1
Link to comment
  • Moderators
3 hours ago, JeViCo said:

Thank you for mentioning this. I use only 0, 90, 180 & 270 degree rotations so it won't cause problems

Unfortunately that might not be the case. For example if you have 2 of those red boxes in each other and rotate 1 of them.

 

There is another method that might be helpful if only 0, 90, 180 270 are used.

Step 1, normalize the width, height and depth. So that rotation doesn't play any role anymore.

https://wiki.multitheftauto.com/wiki/GetElementBoundingBox

getPositionFromElementOffset < https://wiki.multitheftauto.com/wiki/GetElementMatrix

 

Not required: Change your ^imationary^ camera from top to bottom.

 

Get the center position X from both.

 

Compare the distance:

distanceX = [positionX_box1, positionX_box2]

 

if distanceX < (sizeX_box1 / 2) + (sizeX_box2 / 2) then

 

Do the same for the Y and Z axis.

When all are true, there is a collision.

 

 

 

 

 

 

Edited by IIYAMA
  • Like 2
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...