Davidovich Posted August 29, 2009 Share Posted August 29, 2009 I need this function because I want to get the relative point in top of an element and If I change the (rotation) of this element to upside down,the point will be below. The Vehicle/Car = The Element Red Line = Distance The Circle(Ball)= return of the function (x,y,z) [b]function getTopPointRelativeOfElement(element,distance) local x, y, z = getElementPosition ( element ) local rx, ry, rz = getElementRotation ( element ) ... ... return x,y,z end [/b] Link to comment
Gamesnert Posted August 30, 2009 Share Posted August 30, 2009 Overall, it's not extremely hard. You just need to use the function of which I think it has the longest name of em all, and some playing with matrices. - getElementDistanceFromCentreOfMassToBaseOfModel - getElementMatrix Here's what you should do: Use the long function to calculate the distance from the center to the ground. Since it calculates from the center, the distance to the top should be exactly the same. Then, we use getElementMatrix with a slightly modified version of one of the examples on the page: function getPositionFromElementAtOffset(element,x,y,z) if not x or not y or not z then return false end local matrix = getElementMatrix ( element ) local offX = x * matrix[1][1] + y * matrix[2][1] + z * matrix[3][1] + matrix[4][1] local offY = x * matrix[1][2] + y * matrix[2][2] + z * matrix[3][2] + matrix[4][2] local offZ = x * matrix[1][3] + y * matrix[2][3] + z * matrix[3][3] + matrix[4][3] return offX, offY, offZ end Fill in x and y as 0, and z as the distance from the center to the base. In this way, you should have the position above the element. If you want it to be higher up than just the roof, you can always just increase z to get a higher point above the element. This should help you out I hope. Just do note that this is client-side only. Link to comment
Davidovich Posted August 30, 2009 Author Share Posted August 30, 2009 Hey Gamesnert, Thanks For The Reply. I did a alternative, maybe a bit simpler than yours, but isn't as effective as your method is. -.- (Mine can be ServerSide). function getTopPointRelativeOfElement(element,distance) local x, y, z = getElementPosition ( element ) local rx, ry, rz = getElementRotation ( element ) y = y - (distance * math.sin(math.rad(rx)) ) x = x + (distance * math.sin(math.rad(ry)) ) z = z + (distance * math.cos(math.rad(rx+ry)) ) return x,y,z end Man, Thanks alot for helping me by giving Ideas,Methods and Suggestions. (When I Got some free time, I will do some test with your method.) Thanks, Seeya 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