Jump to content

Create object in front of player


Artisz

Recommended Posts

Posted

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. 

Posted
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

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted (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 by Wumbaloo

Computer science student at { EPITECH }

Posted

Thanks, but how can I use it?

Like this?

local x, y, z = getPositionFromElementOffset(source,offX,offY,offZ)

createObjcet(625, x, y, z, .....)

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

IGN: Cordex

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