[Help] Player fly / Noclip with clipping

Yes yes, I know it’s an odd request to make a noclip script that doesn’t allow clipping.

Basically, I want the player to be able to freely fly at an average speed, but also not be able to phase through objects or the world itself. For what I have planned, the player will be invisible anyway so it doesn’t matter how it looks to others or in 3rd person, but it absolutely matters how it looks in first person for the player themselves.

I took some code from es_admin and edited it slightly for the no-clipping side of things to figure out the flying part, it’s just the collisions part I need now…

local heading = 0

Citizen.CreateThread(function()
	while true do
        Citizen.Wait(0)
        
        if droneDeployed then

            if IsControlJustReleased(1,  51) then
                if(noclip == false)then
                    noclip_pos = GetEntityCoords(PlayerPedId(), false)
                end
            
                noclip = not noclip
            end

        end

		if(noclip)then
			SetEntityCoordsNoOffset(PlayerPedId(), noclip_pos.x, noclip_pos.y, noclip_pos.z, 0, 0, 0)

			if(IsControlPressed(1, 34))then
				heading = heading + 1.5
				if(heading > 360)then
					heading = 0
				end

				SetEntityHeading(PlayerPedId(), heading)
			end

			if(IsControlPressed(1, 9))then
				heading = heading - 1.5
				if(heading < 0)then
					heading = 360
				end

				SetEntityHeading(PlayerPedId(), heading)
			end

			if(IsControlPressed(1, 8))then
				noclip_pos = GetOffsetFromEntityInWorldCoords(PlayerPedId(), 0.0, 1.0, 0.0)
			end

			if(IsControlPressed(1, 32))then
				noclip_pos = GetOffsetFromEntityInWorldCoords(PlayerPedId(), 0.0, -1.0, 0.0)
			end

			if(IsControlPressed(1, 152))then
				noclip_pos = GetOffsetFromEntityInWorldCoords(PlayerPedId(), 0.0, 0.0, 1.0)
			end

			if(IsControlPressed(1, 48))then
				noclip_pos = GetOffsetFromEntityInWorldCoords(PlayerPedId(), 0.0, 0.0, -1.0)
			end
		else
			Citizen.Wait(25)
		end
	end
end)

I’m not entirely sure how this could be edited to allow collisions or even just a whole new system. I understand that with getting the player’s coordinate offset in a direction and tping them there every tick they have a key pressed is far from gonna simulate collisions.

Finally, if that’s figured out… Is there a way to detect a collision? Potentially deal damage to the player if they collide with an object or the world? (I know this is all rather advanced now)

1 Like

If nobody has any answers to that, perhaps someone could help me with attaching the game camera to an object, making it follow that object and not the player? And then allowing the player to control the object and not the player anymore

最好的办法是将相机绑定在飞行载具上