Jump to content

Create object in front of player


Artisz

Recommended Posts

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

 

  • Like 1
Link to comment

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 by Wumbaloo
Link to comment

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 by Anzo
  • Like 1
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...