Jump to content

About createcol's rotation


Dretax

Recommended Posts

Interesting.

I wanted to create a code that could open a vehicle door in a fast and logical way, however createcol is not detecting the vehicle? (Client)

function DoorOpener(button, press)
    if not press and button == "mouse2" then
        local px, py, pz = getElementPosition(getLocalPlayer())
		local shape = createColCircle ( px, py, 6)
        outputChatBox("Length " .. #getElementsWithinColShape(shape, "vehicle")) -- Gives 0 back

		for _,v in ipairs(getElementsWithinColShape(shape, "vehicle")) do
			outputChatBox("Car found")
			local getComponent = getVehicleComponents(v)
            for k in pairs (getComponent) do
				local x, y, z = getVehicleComponentPosition(v, k, "world")
                local dist = getDistanceBetweenPoints3D (x, y, z, px, py, pz)
	            outputChatBox("Dist: " .. dist)
	            if dist < 1.5 then
					setVehicleDoorOpenRatio (v, k, 1 - getVehicleDoorOpenRatio(v, k), 0)
	            end
            end
        end
    end
end
addEventHandler("onClientKey", getRootElement(), DoorOpener)

Col is definetely within the vehicle, tested with showcol.

Link to comment
  • Moderators

The centre of the vehicle should be inside the col, otherwise it shouldn't be triggered.

Also you have to take in consideration, that when you use colshapes it can fail to detect elements when they are already inside. This is a big problem serverside, yet for clientside it should be fine.

 

If you can't get it to work use getElementsByType with streamedin argument ON + getDistanceBetweenPoints3D, to solve the issue.

 

 

Link to comment
On 2017. 08. 22. at 01:18, Zorgman said:

Creating cols at say 0,0,-3 relative to your vehicle's position and moving them into position with moveElement won't help with the element hit problems?

 

On 2017. 08. 21. at 23:09, IIYAMA said:

The centre of the vehicle should be inside the col, otherwise it shouldn't be triggered.

Also you have to take in consideration, that when you use colshapes it can fail to detect elements when they are already inside. This is a big problem serverside, yet for clientside it should be fine.

 

If you can't get it to work use getElementsByType with streamedin argument ON + getDistanceBetweenPoints3D, to solve the issue.

 

 

None of them is the case. As I said, the col is within the vehicle. It just doesn't get detected. Lemme get a screenshot for you.

 

UcXafdp.png

 

mXJEgV8.png

 

6m col, definetely within range.

outputChatBox("Length " .. #getElementsWithinColShape(shape, "vehicle")) -- Gives 0 back

Client side.

 

But fine, I will do the streamin thing you suggested, but that might be using a little more.

The moving won't help, since I directly have to check if the vehicle is there or not.

Submitted a bug report.

 

Edited by Dretax
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...