Artisz Posted September 17, 2016 Share Posted September 17, 2016 Hi! How can I do that create an object front of the player. Where can the player look, front of the player. So not that get the player position, add 3 to the x coordinate, and create there, but also get the player rotation, and create the object so that it's in front of the player(the object is a sapling). And how can I do that the player can't place a sapling next to another sapling, what is already placed? I think it's colshape, but how? I am not good in English, sorry. Link to comment
Gravestone Posted September 17, 2016 Share Posted September 17, 2016 For making an object infront of them player I guess you'd need to make some calculations and for the second thing, what is sapling? Link to comment
Artisz Posted September 17, 2016 Author Share Posted September 17, 2016 The young tree, what is going to be a big tree Link to comment
Walid Posted September 17, 2016 Share Posted September 17, 2016 2 hours ago, Gravestone said: For making an object infront of them player I guess you'd need to make some calculations and for the second thing, what is sapling? function getPositionInfrontOfElement(element, meters) if (not element or not isElement(element)) then return false end local meters = (type(meters) == "number" and meters) or 3 local posX, posY, posZ = getElementPosition(element) local _, _, rotation = getElementRotation(element) posX = posX - math.sin(math.rad(rotation)) * meters posY = posY + math.cos(math.rad(rotation)) * meters rot = rotation + math.cos(math.rad(rotation)) return posX, posY, posZ , rot end 1 Link to comment
Wumbaloo Posted September 17, 2016 Share Posted September 17, 2016 (edited) Or 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 Source: getElementMatrix Edited September 17, 2016 by Wumbaloo Link to comment
Artisz Posted September 18, 2016 Author Share Posted September 18, 2016 Thanks, but how can I use it? Like this? local x, y, z = getPositionFromElementOffset(source,offX,offY,offZ) createObjcet(625, x, y, z, .....) Link to comment
Anzo Posted September 18, 2016 Share Posted September 18, 2016 (edited) With the function Matrix is simpler. e.x: objs = {} function objE(player) if objs[player] then destroyElement(objs[player]) end local xb,yb,zb = getElementPosition(player) local rxb,ryb,rzb = getElementRotation(player) local matrixs = (Matrix.create(xb,yb,zb, rxb,ryb,rzb)) local forward = (Matrix.getForward(matrixs) * 2) local positions = (Matrix.getPosition(matrixs) + forward) objs[player] = createObject(625, positions) end addCommandHandler("ob",objE) Just out of curiosity, you want to do a decoration system? Edited September 18, 2016 by Anzo 1 Link to comment
Artisz Posted September 18, 2016 Author Share Posted September 18, 2016 No, it's a forester job. And thanks a lot guys, it's working. 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