miguel360 Posted February 17, 2014 Share Posted February 17, 2014 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) Link to comment
miguel360 Posted February 17, 2014 Author Share Posted February 17, 2014 If i'm making a race gamemode then I want the player to finish when his car's front bumper hits the collisionCuboid. So is this even possible? Link to comment
Moderators Citizen Posted February 17, 2014 Moderators Share Posted February 17, 2014 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. Link to comment
Moderators IIYAMA Posted February 17, 2014 Moderators Share Posted February 17, 2014 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. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now