Jump to content

Just a complex math question


12p

Recommended Posts

I want to create an element in front of the player, at exactly 15 units distance from it,

How can I convert it so it fills the 15 units and nothing else? I have no idea how to do this.

This is my code for getting the X, Y and Z coordinates:

local x2, y2 = getPedTargetCollision ( getLocalPlayer ( ) ) 
if not x2 or not y2 then return end 
local x1, y1, z1 = getElementPosition ( getLocalPlayer ( ) ) 
local x = x1 + ( ( x2 - x1 ) / 3 ) --This gets the X position in front of player, but is relative to the collision. 
local y = y1 + ( ( y2 - y1 ) / 3 ) --This gets the Y position in front of player, but is relative to the collision. 
local z = getGroundPosition ( x, y, z1 + 10 ) 

(Don't care about getPedTargetCollision, I already made the script so it can fit the weapon needing)

EDIT. getPointFromDistanceRotation doesn't work properly.

Link to comment
x2, y2 = getPedTargetCollision ( getLocalPlayer ( ) ) 
if not x2 or not y2 then return end 
local distlimit = 16 
local x1, y1, z1 = getElementPosition ( getLocalPlayer ( ) ) 
local realdist = getDistanceBetweenPoints2D(x1,y1,x2,y2) 
local percdist = distlimit/realdist 
local x = x1 + percdist*(x2 - x1) 
local y = y1 + percdist*(y2 - y1) 
local z = getGroundPosition ( x, y, z1 + 10 ) 

of course it may be wrong if the obstacle is closer than 16 units...

Link to comment
x2, y2 = getPedTargetCollision ( getLocalPlayer ( ) ) 
if not x2 or not y2 then return end 
local distlimit = 16 
local x1, y1, z1 = getElementPosition ( getLocalPlayer ( ) ) 
local realdist = getDistanceBetweenPoints2D(x1,y1,x2,y2) 
local percdist = distlimit/realdist 
local x = x1 + percdist*(x2 - x1) 
local y = y1 + percdist*(y2 - y1) 
local z = getGroundPosition ( x, y, z1 + 10 ) 

of course it may be wrong if the obstacle is closer than 16 units...

it should handle it correctly aswell.

Link to comment
i meant that he pointed out it wouldn't work with closer target, but in fact it does.

i've meant, when you target the building standing next to it, you will get coordinates inside the building, i don't know how this sctipt will be used, so i din't know is that good or bad...

other than that this is definitely not a complex math ;)

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...