Jump to content

Coordinates in front of me


Tekken

Recommended Posts

  • Moderators
38 minutes ago, Tekken said:

Hi I’m trying to create an object just in front of me and attach it to me so it will move as I move, problem is I’m no mathematician :) , an if I’m not mistaking it requires some math.sin math.cos workaround.

 

Greetings.

Check this comment:

 

This can give you the position in front of you or anywhere you want.

Attach elements (static offset) can be done with:

https://wiki.multitheftauto.com/wiki/AttachElements

 

 

 

 

Edited by IIYAMA
  • Like 1
Link to comment

Hi Tekken,

Whenever you attach two elements you can provide offsets relative to the element you are attaching to. Because of this you it shouldn't be too difficult what you're trying to achieve.

I've created a simple script to demonstrate this below. You can provide an offset x, y and z. To spawn something in front of the player, you would have to use y.

attachElements(object, player,0,3,0) -- Y is 3, you could change this to be smaller (closer to the player) or bigger (farther away)



Here's a quick demo script. You can use /cao <objectid> to create something and then /do to detach it in case something goes wrong.



-- Creates object and attaches to player
function createAttachedObjectInFrontOfPlayer(player,objectid)
  local x,y,z = getElementPosition(player)
  local object = createObject(objectid, x,y,z+10)
  return attachElements(object, player,0,3,0)
end


-- Command  to create attached object
addCommandHandler('cao',
function(player, cmd, objectid)
  if not objectid then
    outputChatBox("You didn't provide an object ID!",player,255,0,0)
    return false
  else
    createAttachedObjectInFrontOfPlayer(player,tonumber(objectid))
  end

end
)

-- Detaches whatever you attached to the player.
addCommandHandler('do',
function(player)
  local attached_elements = getAttachedElements(player)
  for i, element in ipairs(attached_elements) do
    detachElements(element,player)
  end
end
)



 

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