vicisdev Posted December 16, 2019 Share Posted December 16, 2019 ENGLISH Let's say I have a player and I want to spawn a car in front of it with a specific distance away from the player. It must considers the player's rotation. It involves some math calculations, but I can't formulate it. BRASIL Vamos supor que eu tenha um player e eu queira spawnar um carro na frente dele com uma distância específica. Para fazer isso, deve levar em consideração a rotação atual do player. Eu sei que isso envolve cálculos matemáticos, mas não consegui formulá-los. Thanks all Link to comment

Space_Unicorn Posted December 16, 2019 Share Posted December 16, 2019 https://wiki.multitheftauto.com/wiki/GetElementMatrix function getPositionFromElementOffset(element,offX,offY,offZ) local m = getElementMatrix ( element ) -- Get the matrix local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] -- Apply transform local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] return x, y, z -- Return the transformed point end 1 Link to comment

vicisdev Posted December 16, 2019 Author Share Posted December 16, 2019 1 hour ago, Space_Unicorn said: https://wiki.multitheftauto.com/wiki/GetElementMatrix function getPositionFromElementOffset(element,offX,offY,offZ) local m = getElementMatrix ( element ) -- Get the matrix local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] -- Apply transform local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] return x, y, z -- Return the transformed point end Uuuuh wee! It works like a charm! Thank you! 1 Link to comment

Motar2k Posted December 17, 2019 Share Posted December 17, 2019 (edited) function getFrontPosition(element,dist) local x, y, z = getElementPosition(element) local _,_,r = getElementRotation(element) local tx = x + - ( dist ) * math.sin( math.rad( r ) ) local ty = y + dist * math.cos( math.rad( r ) ) local tz = z return tx,ty,tz end Edited December 17, 2019 by Avival 2 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 account## Sign in

Already have an account? Sign in here.

Sign In Now