Jump to content

Collision of two vehicles


FatalTerror

Recommended Posts

Hi community users,

I start make a script for my server and I realized something. I will seek help on the wiki to find an event when two vehicles to touch.

But I found nothing.

If you know how do if a vehicle was touch by another and have the element of the other vehicle. Thx to help me :oops:

Thanks !

Link to comment

You can create a variable (element data) on the vehicle called "colliding".

Then, use a timer or onClientRender, and set its handler function to check if there is any element else in a rectangle colshape than the vehicle itself, and if that element is a vehicle. If the variable colliding was false, then set it to true and trigger the event you wish.

Link to comment

The player doesn't get damaged when crashing with vehicle.

So how i do?

Let me explain the idea from the beginning ...

When the script starts, I have a random player. He will be the mouse.

And all others will be cats, which first hit the mouse earns a certain amount.

And I need the player who hit the mouse.

He didn't mention the vehicle here, so I thought he wanted the script different, instead.

Link to comment
So how i do?

Let me explain the idea from the beginning ...

When the script starts, I have a random player. He will be the mouse.

And all others will be cats, which first hit the mouse earns a certain amount.

And I need the player who hit the mouse.

Possible or not? :?

Hard to say.

It would require a lot of math.

Link to comment

Hm i will test with onPlayerDamage()...

When the mouse is damage, I need to know which player is closest to the mouse, but for her I'm lost

addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), 
function() 
    theMouse = getRandomPlayer() 
end) 
  
addEventHandler("onPlayerDamage", getRootElement(), 
function() 
    if (source == theMouse)then 
        local mX, mY, mZ = getElementPosition(theMouse) 
        for i, thePlayer in ipairs ( getElementsByType("player") ) do 
            local pX, pY, pZ = getElementPosition(thePlayer) 
            local distance = getDistanceBetweenPoints3D ( mX, mY, mZ, pX, pY, pZ ) 
             
            -- And after this i'm lost o_O 
        end 
    end 
end) 

I don't find other solution :?

Edited by Guest
Link to comment
Hm i will test with onPlayerDamage()...

When the mouse is damage, I need to know which player is closest to the mouse, but for her I'm lost

addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), 
function() 
    theMouse = getRandomPlayer() 
end) 
  
addEventHandler("onPlayerDamage", getRootElement(), 
function() 
    if (source == theMouse)then 
        local mX, mY, mZ = getElementPosition(theMouse) 
        for i, thePlayer in ipairs ( getElementsByType("player") ) do 
            local pX, pY, pZ = getElementPosition(thePlayer) 
            local distance = getDistanceBetweenPoints3D ( mX, mY, mZ, pX, pY, pZ ) 
             
            -- And after this i'm lost o_O 
        end 
    end 
end) 

I don't find other solution :?

did you see my other post? i put a download link to my script that works the same way.

Download it and use it...

In my script i check which players gets damaged between each 50ms' and compare distances between the players that got damaged to the length of both vehicles being compared.

Link to comment
...

In my script i check which players gets damaged between each 50ms' and compare distances between the players that got damaged to the length of both vehicles being compared.

What about if there are 2 vehicles close to the hit player and the one that didn't hit is closer to the one that did hit? As you probably know by now, vehicle's position is the pivot position of the vehicle (most of the cars have it in the middle). So, distance between vehicle hitting from the front is longer than vehicle hitting from the side. Also, remember, vehicle size varies.

2pynzhl.png

Link to comment
...

In my script i check which players gets damaged between each 50ms' and compare distances between the players that got damaged to the length of both vehicles being compared.

What about if there are 2 vehicles close to the hit player and the one that didn't hit is closer to the one that did hit? As you probably know by now, vehicle's position is the pivot position of the vehicle (most of the cars have it in the middle). So, distance between vehicle hitting from the front is longer than vehicle hitting from the side. Also, remember, vehicle size varies.

2pynzhl.png

Yes, but its still pretty accurate because if the vehicle that was closer did not hit the vehicle, then its unlikely that it got damaged, which would mean that the vehicle that was further away and hit the "mouse" would be counted as the one that hit it. And still, using getElementBoundingBox is and calculating distance with rotation in 3d would still not be accurate because the vehicles are not rectangles, so the way i used is probably the best way without destroying ones brain.

Link to comment
The colshape doesn't really work, since its bigger than the object itself.

not sure, but may work, how getElementColShape() works?

if it doesn't, just use two processLineOfSight targeted at opposite vehicle ignoring your vehicle, and add up the vector length you got.

if the added vector length is not much longer(+/-20cm) then distance between vehicles, you have got a hit.

PS:as this is cpu intense, you should still use copshapes/watever to detect what vehicles to check.

this should work on 90% of cases, that is when collision point in the line between vehicles is closest to opposite vehicle.

Link to comment

The idea which checks the damage of both vehicles with a check if the damage could be done is the best.

A fairly different idea is of course to do it client side, so that every cat checks whats in front of it (as seen above) which triggers when the line of sight gets disturbed.

And the most cheater-and-lagger proof idea should be to create a collision check server side (for vehicles only, of course) which finds out which element hit which just by checking a 3D col shape.

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...