Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normal to rotation #431

Merged
merged 2 commits into from
Oct 23, 2023
Merged

Conversation

Demigod916
Copy link
Contributor

@Demigod916 Demigod916 commented Oct 2, 2023

this small addition allows developers to pass in a surface normal and get a rotation vector in return. this function has been useful in object placement, spray paints, decals, etc.

docs are done as well here

RegisterCommand("testnormalrot", function()
  lib.requestModel(`prop_mp_cone_01`)

  local playerCoords = GetEntityCoords(cache.ped)

  local object = CreateObject(`prop_mp_cone_01`, playerCoords.x, playerCoords.y, playerCoords.z, false, false, false)

  SetEntityAlpha(object, 200)
  SetEntityRotation(object, rot.x, rot.y, rot.z, 1)
  DisableCamCollisionForEntity(object)
  SetEntityCollision(object, false, false)
  SetEntityDrawOutlineColor(10, 170, 210, 200)
  SetEntityDrawOutlineShader(0)
  SetEntityDrawOutline(object, true)
  while true do
      _, _, endCoords, surfaceNormal = lib.raycast.cam()
      rot = lib.math.normaltorotation(surfaceNormal)
      SetEntityCoords(object, endCoords)
      SetEntityRotation(object, rot.x, rot.y, rot.z, 1)

      if IsControlJustPressed(0, 18) then
          return
      end
  end
end)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants