Xwad Posted March 19, 2019 Share Posted March 19, 2019 Hello. I wan't to determine which side of the vehicle was shooted (front or rear). My problem is that the front and the rear will be the opposite when the vehicle is rotated 180 deegres. I know, i have to use getOffsetFromXYZ but i dont really understand the logic. function onFire(weapon,ammo,ammoInClip,hitX,hitY,hitZ,hitElement) if getElementType(hitElement) == "vehicle" then local x,y,z = getOffsetFromXYZ( getElementMatrix(hitElement), getElementPosition(hitElement) ) local offsetX = hitX - x local offsetY = hitY - y local offsetZ = hitZ - z if offsetX > 0 then outputChatBox("rear") elseif offsetX < 0 then outputChatBox("front") end end end addEventHandler("onClientPlayerWeaponFire", root, onFire) function getOffsetFromXYZ( mat, vec ) -- make sure our matrix is setup correctly 'cos MTA used to set all of these to 1. mat[1][4] = 0 mat[2][4] = 0 mat[3][4] = 0 mat[4][4] = 1 mat = matrix.invert( mat ) local offX = vec[1] * mat[1][1] + vec[2] * mat[2][1] + vec[3] * mat[3][1] + mat[4][1] local offY = vec[1] * mat[1][2] + vec[2] * mat[2][2] + vec[3] * mat[3][2] + mat[4][2] local offZ = vec[1] * mat[1][3] + vec[2] * mat[2][3] + vec[3] * mat[3][3] + mat[4][3] return {offX, offY, offZ} end Link to comment
Moderators IIYAMA Posted March 19, 2019 Moderators Share Posted March 19, 2019 (edited) local posX, posY, posZ = getElementPosition(hitElement) local offsetX, offsetY, offsetZ = getOffsetFromXYZ(getElementMatrix(hitElement), posX - hitX, posY - hitY, posZ - hitZ) The matrix is already containing the position of the vehicle. Untested and not even sure if this is the right approach. @Xwad P.s this function can return the surface position:https://wiki.multitheftauto.com/wiki/ProcessLineOfSight normalX, normalY, normalZ Edited March 19, 2019 by IIYAMA Link to comment
Moderators IIYAMA Posted March 19, 2019 Moderators Share Posted March 19, 2019 nvm that is probably not going to work. Link to comment
Discord Moderators Pirulax Posted March 20, 2019 Discord Moderators Share Posted March 20, 2019 I'd just get the angle between the hit pos and vehicle's pos + vehicle.rotation.z, thats it. Link to comment
Xwad Posted March 21, 2019 Author Share Posted March 21, 2019 And which function should i use for getting the angle? 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