Author Topic: Point to Vector  (Read 580 times)

Motley

  • Full Member
  • ***
  • Posts: 251
  • Karma: +32/-34
    • View Profile
Point to Vector
« on: December 31, 2020, 07:09:24 pm »
I tried writing this the right way with what I would have to assume is with

Code: [Select]
atan2(x1, y1) - atan2(x2, y2)
Regardless to what formula I tried it was just a really low end return. I wrote a bypass for now to get the job done. Whenever I find the time to create this the right way as mentioned I will upload that version! I even tried rotating around x and y to create a circle around the player with a math formula. Like a rotating camera to player position. Hopefully eventually I'll figure out the right way to do stuff.

I'll make sure you can swap this concept out for the right version later.

I learned that LU prefers to receive angles for player in degrees. It automatically gets converted to radians angle in:

Code: [Select]
Player.Angle
Derp..



Also I'm not sure if I did something wrong but the compass rose rotation is backwards in this script. Maybe it's just LU or something. Or maybe documented positions wrong as it was weird when I tried learning everything
 
Code: [Select]
GetAngle(Point)
is backwards derp.. I obviously acknowledged that was weird and kept thinking derp during testing.



No Idea. Here Is GetAngle function:

Code: [Select]
function GetAngle(Point) {
  if (Point == "North") return 0;
  else if (Point == "West" ) return 90;
  else if (Point == "South") return 180;
  else if (Point == "East" )return 270;
  else if (Point == "NorthWest" ) return 50;
  else if (Point == "SouthEast" ) return 220;
  else if (Point == "SouthWest" ) return 140;
  else if (Point == "NorthEast" )return 310;
}



The next function is my main function. Point to Vector:

Code: [Select]
function PointToDirection(entity, Goto) {
 
  // Some array that gets each cord and sets the closest direction first, then second etc
  local MyCompass = [ 0, 1, 2, 3, 4, 5, 6, 7 ];
  local MyPoint = {};
 
  MyPoint.rawset(MyCompass[0] = GetDistance(Goto, Vector(entity.Pos.x, entity.Pos.y+4, entity.Pos.z)), "North" );
  MyPoint.rawset(MyCompass[1] = GetDistance(Goto, Vector(entity.Pos.x, entity.Pos.y-4, entity.Pos.z)), "South");
  MyPoint.rawset(MyCompass[2] = GetDistance(Goto, Vector(entity.Pos.x+4, entity.Pos.y, entity.Pos.z)), "East" );
  MyPoint.rawset(MyCompass[3] = GetDistance(Goto, Vector(entity.Pos.x-4, entity.Pos.y, entity.Pos.z)), "West");
 
  MyPoint.rawset(MyCompass[4] = GetDistance(Goto, Vector(entity.Pos.x+3, entity.Pos.y+3, entity.Pos.z)), "NorthEast");
  MyPoint.rawset(MyCompass[5] = GetDistance(Goto, Vector(entity.Pos.x+3, entity.Pos.y-3, entity.Pos.z)), "SouthEast");
 
  MyPoint.rawset(MyCompass[6] = GetDistance(Goto, Vector(entity.Pos.x-3, entity.Pos.y+3, entity.Pos.z)), "NorthWest");
  MyPoint.rawset(MyCompass[7] = GetDistance(Goto, Vector(entity.Pos.x-3, entity.Pos.y-3, entity.Pos.z)), "SouthWest");
 
  MyCompass.sort()
  entity.Angle = GetAngle(MyPoint.rawget(MyCompass[0]))
}

I did my best to keep it short and lightweight on data.
I'm probably going to do some client scripting and add the compass rose at some point and attempt to rotate it based of angle change. I think it will teach me a few things derp
« Last Edit: December 31, 2020, 07:22:51 pm by Motley »

 

© Liberty Unleashed Team.