Jump to content

Help! getElementColShape


miguel360

Recommended Posts

Posted

I want to get vehicles colShape and if the vehicles colshape hits the cuboid it should display "hit"!

  
cuboid = createColCuboid ( 2043.2, -2608, 12.6, 0.4, 13.5, 1 ) 
  
function test() 
veh = getPedOccupiedVehicle( source ) 
setElementCollisionsEnabled ( veh, true ) 
col1 = getElementColShape( veh ) 
end 
addEventHandler("onPlayerVehicleEnter", getRootElement(), test) 
  
function hit1( box ) 
if (box == cuboid) then 
if (isElementWithinColShape (col1 , cuboid) == true) then 
outputChatBox("hit", root) 
end 
end 
end 
addEventHandler ("onElementColShapeHit", getRootElement(), hit1) 
  
  

  • Moderators
Posted

Yeah of course, look at this code:

cuboid = createColCuboid ( 2043.2, -2608, 12.6, 0.4, 13.5, 1 ) 
  
function hit1( box ) 
    if (box == cuboid) then 
        outputChatBox("Hey something just hitted the cuboid colshape !") 
         
        if getElementType(source) == "vehicle" then 
            outputChatBox("Oh ! and it is a vehicle !") 
  
            local thePlayer = getVehicleController(source) 
            local playerName = getPlayerName(thePlayer) 
            outputChatBox("And the guy who is driving is "..tostring(playerName)) 
  
        end 
    end 
end 
addEventHandler ("onElementColShapeHit", getRootElement(), hit1) 

I added some outputs to better understand what is going on.

  • Moderators
Posted

This won't trigger when it's front bumper enters the colshape. Only when the centre of the element is inside.

The only way of calculate this is by rendering at clientside and checking positions.

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