Jump to content

Create arrow pointing an element


'LinKin

Recommended Posts

Posted (edited)

Hello,

When I create an arrow and attach it to a player, I want it to be visible only for the player that it's attached to..

How can I do that via serverside?

setElementVisibleTo ( theArrow, getRootElement(), false ) did not work.. Everyone can see the arrow

Edited by Guest

Need a clanwar script? Click here!

Do you want some free scripts for your DD server? Visit my website.

Posted

Hm

Does someone know how can I rotate the arrow so that it points to a moving vehicle everytime?

It's kinda hard because the vehicle is on movement...

Need a clanwar script? Click here!

Do you want some free scripts for your DD server? Visit my website.

Posted

(Not Tested)

  
local car = createVehicle ( 0, 0, 0 ) 
local arrow = createObject ( the_arrow_id, 0, 0, 0 ) 
addEventHandler ( "onClientPreRender", root, function ( ) 
  local cx, cy, cz = getElementPosition ( car ) 
  local x, y, z = getElementPosition ( localPlayer ) 
  local rot = findRotation ( cx, cy, x, y ) 
  setElementPosition ( arrow, x, y, z + 1 ) 
  setElementRotation ( arrow, 0, 0, rot ) 
end ) 
  
  
  
function findRotation(x1,y1,x2,y2) 
  
  local t = -math.deg(math.atan2(x2-x1,y2-y1)) 
  if t < 0 then t = t + 360 end; 
  return t; 
  
end 
  

Posted

Also.

Is it possible that the arrow points to a target in 3D? I mean, I see most of GPS systems just turn the arrow horizontally.

Is it possible to make an arrow point to the target vertically too?

For example; If the target is under you, it points down. If target's over you, it points up. If target's diagonally, it points diagonally (vertical & horizontal rotation)

Need a clanwar script? Click here!

Do you want some free scripts for your DD server? Visit my website.

Posted
Also.

Is it possible that the arrow points to a target in 3D? I mean, I see most of GPS systems just turn the arrow horizontally.

Is it possible to make an arrow point to the target vertically too?

For example; If the target is under you, it points down. If target's over you, it points up. If target's diagonally, it points diagonally (vertical & horizontal rotation)

It is, but you'd need to make your own "findRotation" function for that.

Posted
function GPS:update() 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    if not vehicle then 
        self:stopNavigation() 
        return 
    end 
     
    local x, y, z = getElementPosition(vehicle) 
    local horizontalRotation = findRotation(x, y, self.m_Destination.X, self.m_Destination.Y) - 90 
    local verticalRotation = math.deg(math.asin((self.m_Destination.Z - z) / getDistanceBetweenPoints3D(self.m_Destination.X, self.m_Destination.Y, self.m_Destination.Z, x, y, z))) 
     
    setElementPosition(self.m_Arrow, x, y, z + 1) 
    setElementRotation(self.m_Arrow, 0, 90 + verticalRotation, horizontalRotation) 
end 

Posted

It's a function that calculates the rotation you need to point to a specified position.

Transferred to your code:

local car = createVehicle ( 0, 0, 0 ) 
local arrow = createObject ( the_arrow_id, 0, 0, 0 ) 
addEventHandler ( "onClientPreRender", root, function ( ) 
  local cx, cy, cz = getElementPosition ( car ) 
  local x, y, z = getElementPosition ( localPlayer ) 
  local rotH = findRotation ( cx, cy, x, y ) - 90 
  local rotV = math.deg(math.asin((cz - z) / getDistanceBetweenPoints3D(cx, cy, cz, x, y, z))) 
  setElementPosition ( arrow, x, y, z + 1 ) 
  setElementRotation ( arrow, 0, 90 + rotV, rotH ) 
end ) 

Posted

Thanks.

Now I'm looking at Jusonex's script and I see that the arrow that he creates is different from the one I create..

I'm currently using this arrow_id = 1318

Jusonex, can you tell me which arrow_id you're using? Because yours is way better than mine. (More visible, understable)

This is what my arrow looks like:

http://i.imgur.com/Owe1rs0.png

http://i.imgur.com/tCcJsCn.png

Need a clanwar script? Click here!

Do you want some free scripts for your DD server? Visit my website.

Posted

I posted this some days ago:

function findPitch(camerax,cameray,cameraz,pointx,pointy,pointz) 
  
local dX=camerax-pointx 
local dY=cameraz-pointz 
local dZ=cameray-pointy 
  
local pitch=math.atan2(dY,math.sqrt(math.pow(dZ,2) + math.pow(dX,2))); 
return pitch 
end 

It's returning in radians, so you need to convert it to degrees:

local degree = pitchReturn*(180/math.pi) 

pitchReturn = The "findPitch" function.

It's the same as findRotation but then for the X rotation (up and down) so if someone is underneath you it will calculate the position under you. Here's a little example with a plane:

 function findYaw(x1,y1,x2,y2) 
  
  local zRot = -math.deg(math.atan2(x2-x1,y2-y1)) 
  if zRot < 0 then zRot = zRot + 360 end; 
  return zRot; 
  
end 
  
  
function findPitch(camerax,cameray,cameraz,pointx,pointy,pointz) 
  
local dX=camerax-pointx 
local dY=cameraz-pointz 
local dZ=cameray-pointy 
  
local pitch=math.atan2(dY,math.sqrt(math.pow(dZ,2) + math.pow(dX,2))); 
return pitch 
end 
  
  
car = createVehicle ( 513, 0,0, 10 ) 
  
  
addEventHandler ( "onClientPreRender", root, function () 
    local x,y,z = getElementPosition (localPlayer) 
    local pointX, pointY, pointZ = getElementPosition ( car ) 
    local rotZ = findYaw(pointX, pointY,x,y) 
    local rotX = findPitch(pointX,pointY,pointZ, x,y,z) 
    local degreePitch = rotX*(180/math.pi) 
    setElementPosition ( car, 0,0, 10 ) 
    setElementRotation ( car,-degreePitch,0,rotZ) 
end) 
  
  

findYaw is the same function as "findRotation".

Edit: Put the degree return always in the "-", or else it will point the other way

Regards,

Danny

Sometimes I dream about cheese

Posted

Thanks Danny, arezu, Justonex. As I said, it's working fine, the horizontal and vertical rotation is perfect. I was just asking for the model of the arrow, because my arrow is different from others.. I don't know why.

Im using the same model as others. Maybe it is something else that changes its aspect?

Need a clanwar script? Click here!

Do you want some free scripts for your DD server? Visit my website.

Posted

I'm not a pro at math but the solution is quite simple as I see. In shooter maps we always shoot rockets in straight direction, so you want that arrow to be in straight direction, right? So download an shooter map and there should be 4 lines where math.cos is used, just use thèse four lines to get the position and to to keep the arrow in straight direction and add onClientRender to get the rotation. Right now I'm away from home, once I'm back. I'll help you then.

Posted

If you use onClientRender, the arrow is very laggy. onClientPreRender smooths it out.

this is based on what??..

My ingame nick is ~HyPeX~

BF3 Gamemode Progress: ~30% - Currently working on AI & MapManager

gKhdyRJ.png

Posted
Gosh.

Arrow is pointing ok!

I'm asking about the model of the arrow. Visual aspect

Whats wrong with the model, is it to small, or to big??

Sometimes I dream about cheese

Posted

Need a clanwar script? Click here!

Do you want some free scripts for your DD server? Visit my website.

Posted

Hmm, do you have any shaders on the server?

Also try to disable all the textures on the server, and also to set the time to 12:00 to see any difference..

Sometimes I dream about cheese

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