|
 |
| Author |
Message |
|
Domino
|
Posted: 30 Jan, 2012
|
|
Joined: 26 Feb, 2009 Posts: 2996
|
|
Hi,
Anyone know how to convert a vector angle to a heading?
The question should have been:
How do i find the angle between 2 units, taking into account the direction the first unit is facing.
_________________ Domino. ______________
Last edited by Domino on 06 Feb, 2012, edited 1 time in total.
|
|
| Top |
|
 |
|
BulletMagnet
|
Posted: 30 Jan, 2012
|
|
Joined: 05 Oct, 2007 Posts: 16424 Location: camping near the biggest power-up
|
|
What's this for? You might need a quaternion for it, or just a pair of angles.
_________________
Nephylim wrote: But, an FA army in an FA environment just looks... right. Does anyone know how to use air transports? I cant get them to pick up troops.
|
|
| Top |
|
 |
|
Domino
|
Posted: 31 Jan, 2012
|
|
Joined: 26 Feb, 2009 Posts: 2996
|
|
i need to figure out how to make a units buildbone turn to face a target, i can get the quartinion, and convert it to an angle, either or..
however the build manipulator takes a heading as its turn params.. i have no idea how to turn a quartinion or angle into a heading.
ive tried many things, like adding another rotator and rotating the body to face the target, rotators take whole numbers.. like 10, 11, 15 its not an angle or a quartitnion so again the angle would need converting to the rotators "param" i do not know how to achive this either..
i think the best thing is to turn the quartinion or angle into a heading and use the buildarm manipulator directly.
any ideas?
_________________ Domino. ______________
|
|
| Top |
|
 |
|
BulletMagnet
|
Posted: 31 Jan, 2012
|
|
Joined: 05 Oct, 2007 Posts: 16424 Location: camping near the biggest power-up
|
|
How do existing build arms do it?
_________________
Nephylim wrote: But, an FA army in an FA environment just looks... right. Does anyone know how to use air transports? I cant get them to pick up troops.
|
|
| Top |
|
 |
|
Domino
|
Posted: 31 Jan, 2012
|
|
Joined: 26 Feb, 2009 Posts: 2996
|
|
no idea the code is in the engine..
the manipulator takes a heading, this is why i need to convert a quartinion or angle to a heading..
_________________ Domino. ______________
|
|
| Top |
|
 |
|
BulletMagnet
|
Posted: 31 Jan, 2012
|
|
Joined: 05 Oct, 2007 Posts: 16424 Location: camping near the biggest power-up
|
Code: math.atan2(z, x) This should give you (in radians) the compass bearing from East. The pitch should be; Code: math.atan2(y, math.sqrt(z * z + x * x)) I do believe that y is height, as with most game engines. If I'm mistaken, then swap things around until they work better. x, y, and z are the distances from the turret to the target. [PS:] Still don't really understand why you're doing this manually. I thought the engine let you tell the unit to rep/assist/build something and it'd point all the BuildArmManipulators for you.
_________________
Nephylim wrote: But, an FA army in an FA environment just looks... right. Does anyone know how to use air transports? I cant get them to pick up troops.
|
|
| Top |
|
 |
|
Domino
|
Posted: 31 Jan, 2012
|
|
Joined: 26 Feb, 2009 Posts: 2996
|
Hi, you dont need to understand my friend, its actually for an ability/order i have put on the seraphim commander, you may have seen it.. the resurrection ability.. this ability is totally independant to all other orders in essense a completely new order, completely driven by its own code.. because of this, it obviously doesnt call any unit functions as it uses its own.. the only problem with this is that although i can move the acu to a unit/wreck to resurrect it.. i am having problems rotating the body to face the target, if say i send it to resurrect a group of wrecks and one is behind the acu but in range to resurrect, the body doesnt turn to face the target.. so the effects beams just fires out from the bone position/facing to the target.. im sure you can visualize how that looks..  if your code works ill have your babies, as this is the 2nd last piece in the puzzle to making new orders ect.. making units turn to targets.. the other is order lines.. but for the life of me, i have no idea yet about that.. well i do with the use of decals.. i havent looked properly yet though.. 
_________________ Domino. ______________
|
|
| Top |
|
 |
|
Domino
|
Posted: 01 Feb, 2012
|
|
Joined: 26 Feb, 2009 Posts: 2996
|
|
Hi,
BM, usingt he buildmanipulator wont work, because we can only snap the manip to the position... which sucks..
so ive added a rotator to the buildbones... now the problem is as before... that i canont get the correct angle between the unit facing direction to the wreck position to feed to the rotator...
do you know how to return the correct angel in degrees using the units buildbones as the base direction.?
_________________ Domino. ______________
|
|
| Top |
|
 |
|
BulletMagnet
|
Posted: 01 Feb, 2012
|
|
Joined: 05 Oct, 2007 Posts: 16424 Location: camping near the biggest power-up
|
Domino wrote: do you know how to return the correct angel in degrees using the units buildbones as the base direction.? Try my code, with the unit facing East and then North, and see if it's close to being right. If it is, then we can work from there. Otherwise, I'll have to revise my maths.
_________________
Nephylim wrote: But, an FA army in an FA environment just looks... right. Does anyone know how to use air transports? I cant get them to pick up troops.
|
|
| Top |
|
 |
|
Domino
|
Posted: 01 Feb, 2012
|
|
Joined: 26 Feb, 2009 Posts: 2996
|
Hi, Well, i cant use the atan approach, because i was going to use those numbers with the units buildmanipulator BUT i cant use this manip because there is only one control for movement for this type of manip, which is SetHeadingPitch(x,y) its doesnt move the units... its snaps them to the position.. which is useless, as i need to the unit to rotate... so ive setup some rotators, on the buildbones.. and i thought that GetAngleBetween(pos1, pos2) would return the correct angle between the vectors, however it doesnt.. it returns radians i think.. Code: function GetAngleInBetween(v1, v2) #normalize the vectors local vec1 = {} local vec2 = {} vec1 = NormalizeVector(v1) vec2 = NormalizeVector(v2) local dotp = DotP(vec1, vec2) return math.acos(dotp)*(360/(math.pi*2)) end this return 0.74335807561874 with the acu facing south and the wreck to the east.. when the acu is facing south again and the wreck to the west it returns 0.55249279737473i can get degrees by again multiplying the radian angle between *(360/(math.pi*2))ive no idea if this is correct OR if the angle function is returning the correct angle between the vectors.. the rotator need a degree angle to turn to..
_________________ Domino. ______________
|
|
| Top |
|
 |
|
BulletMagnet
|
Posted: 01 Feb, 2012
|
|
Joined: 05 Oct, 2007 Posts: 16424 Location: camping near the biggest power-up
|
Okay, after consulting Wikipedia, I see what you're doing there, and my only conclusion is that it's giving you the size of the angle between the two vectors (which is what it's technically claims to do). What you need to do is get the angle from East for both vectors, and then subtract the difference. It should mean that negative angles are in one direction, and positive are in the other. The problem is, I don't think your method will let you get that. Going to do some more thinking. [EDIT:] Arctan to the rescue! Code: local v = VDiff(self:GetPosition(), target:GetPosition()) angle = math.atan2(v.z, v.x) Before converting to degrees (don't do that yet, it's your next step) work out what this is doing. Don't face the ACU South. Face it East, and have the turret face forward. Spam all your results to log, post them here.
_________________
Nephylim wrote: But, an FA army in an FA environment just looks... right. Does anyone know how to use air transports? I cant get them to pick up troops.
|
|
| Top |
|
 |
|
Domino
|
Posted: 01 Feb, 2012
|
|
Joined: 26 Feb, 2009 Posts: 2996
|
here is some numbers and what i observe...ill explain what ive done Code: INFO: YawDegrees 47.388389587402 INFO: YawRadians 0.4135417342186
INFO: YawDegrees 26.533275604248 INFO: YawRadians 0.23154652118683
INFO: YawDegrees 51.143478393555 INFO: YawRadians 0.44631105661392
INFO: YawDegrees 53.883483886719 INFO: YawRadians 0.47022214531898
INFO: YawDegrees 34.379112243652 INFO: YawRadians 0.30001437664032
INFO: YawDegrees 40.92981338501 INFO: YawRadians 0.35718002915382
local YawRadians = util.GetAngleInBetween(self:GetPosition(), wreck:GetPosition()) local YawDegrees = YawRadians*(360/(math.pi*2)) *2
ok looking that.. it seems it is giving the correct radian and angle, ive checked online using a radian calculator, i times the angle result by 2 for testing.. first set of numbers is the acu facing southand and the unit to the east.. second set of numbers is the acu facing south with the unit to the west.. on what i observe with the rest of the numbers... is this.. if the acu is facing south and i put the unit within the nw angle before west, the unit lines up with the target fine.. every time.. as soon as the unit position goes past west, the acu turns from north to the angle of the unit in the west position... hard to explain. umm its turning the degree from north.. when the unit is west. if the unit is west + 1 then the acu turns to the positon north +1 it seems it only lines up with the target in the nw position before lateral west, it also seems that angles from north to north are in 4 quadrants using 90 degree angles then they reset, thats what it looks like. i could be talking nonesense, do you understand what ive said..
_________________ Domino. ______________
Last edited by Domino on 01 Feb, 2012, edited 1 time in total.
|
|
| Top |
|
 |
|
Domino
|
Posted: 01 Feb, 2012
|
|
Joined: 26 Feb, 2009 Posts: 2996
|
|
Hi,
just doing a quick video to show you.. hold on 5 mins.
_________________ Domino. ______________
|
|
| Top |
|
 |
|
Domino
|
Posted: 01 Feb, 2012
|
|
Joined: 26 Feb, 2009 Posts: 2996
|
here is the video example pal.. http://youtu.be/9tqpnUwBQscas you can see it seems to work fine for lower nw positions,
_________________ Domino. ______________
|
|
| Top |
|
 |
|
BulletMagnet
|
Posted: 01 Feb, 2012
|
|
Joined: 05 Oct, 2007 Posts: 16424 Location: camping near the biggest power-up
|
I didn't understand that, mainly because of poor grammar and spelling. Face. East. Maths ALWAYS starts at East. East is the start, and East is the finish. Since we're dealing with maths and numbers, we should follow their rules. This is what I want you to test; 1. Face the ACU East. 2. Put out four wrecks; North, South, East, and West of the ACU. 3. Check all four situations, without moving the ACU any further.
_________________
Nephylim wrote: But, an FA army in an FA environment just looks... right. Does anyone know how to use air transports? I cant get them to pick up troops.
|
|
| Top |
|
 |
|
Domino
|
Posted: 01 Feb, 2012
|
|
Joined: 26 Feb, 2009 Posts: 2996
|
ok, Code: INFO: YawDegrees 51.042896270752 INFO: YawRadians 0.44543331861496
INFO: YawDegrees 22.555271148682 INFO: YawRadians 0.19683188199997
INFO: YawDegrees 73.315933227539 INFO: YawRadians 0.63980221748352
INFO: YawDegrees 24.203763961792 INFO: YawRadians 0.21121770143509 http://youtu.be/HVH1doyH0NEit doesnt face any of the targets.. :/
_________________ Domino. ______________
|
|
| Top |
|
 |
|
BulletMagnet
|
Posted: 01 Feb, 2012
|
|
Joined: 05 Oct, 2007 Posts: 16424 Location: camping near the biggest power-up
|
|
Also, lolololol. We both missed something. We're working in 3D here. The height of the ACU may be being considered when we really don't want it.
_________________
Nephylim wrote: But, an FA army in an FA environment just looks... right. Does anyone know how to use air transports? I cant get them to pick up troops.
|
|
| Top |
|
 |
|
Domino
|
Posted: 01 Feb, 2012
|
|
Joined: 26 Feb, 2009 Posts: 2996
|
|
are you sure we only want a 2d angle in a 3d enviroment?
if thats the case a new function is needed to calc the radian in 2d
_________________ Domino. ______________
|
|
| Top |
|
 |
|
Domino
|
Posted: 01 Feb, 2012
|
|
Joined: 26 Feb, 2009 Posts: 2996
|
|
we prolly also need to calc in somehow the direction the acu is facing..
gimme a few mins ill write a new function to calc the radian in 2d
_________________ Domino. ______________
|
|
| Top |
|
 |
|
Domino
|
Posted: 01 Feb, 2012
|
|
Joined: 26 Feb, 2009 Posts: 2996
|
|
i think we defo need a 3d vector returned using the 2d method yeilds results that are useless pal, degrees of 1 and 1.4 for a 45 degree rotation,
_________________ Domino. ______________
|
|
| Top |
|
 |
|
BulletMagnet
|
Posted: 01 Feb, 2012
|
|
Joined: 05 Oct, 2007 Posts: 16424 Location: camping near the biggest power-up
|
|
Post codes.
_________________
Nephylim wrote: But, an FA army in an FA environment just looks... right. Does anyone know how to use air transports? I cant get them to pick up troops.
|
|
| Top |
|
 |
|
Domino
|
Posted: 01 Feb, 2012
|
|
Joined: 26 Feb, 2009 Posts: 2996
|
its actually very simple at the moment, as im just trying to get the unit to point to the target so. Code: local YawRadians = util.GetAngleInBetween(self:GetPosition(), wreck:GetPosition()) local YawDegrees = YawRadians * (360/(math.pi*2)) which does return the correct radians and shows the correct degrees IF the target location is in the north / northwest quadrant with the acu facing south. it also works ok if the acu is facing east and the target is in the east / north east quadrant. the thing that i dont get is that in the previous function posted GetAngleBetween() the function already calc's in the * (360/(math.pi*2)) yet i have to do it again in my code to get the correct degree from the radians. resin mentioned something last night that it uses a 4 quadrant thingy or something or other.. i think this may be right, because as ive said when angles are returned for different quadrants n/e/s/w the turn is almost always to the nw quadrant, whatever the angle is.
_________________ Domino. ______________
|
|
| Top |
|
 |
|
BulletMagnet
|
Posted: 01 Feb, 2012
|
|
Joined: 05 Oct, 2007 Posts: 16424 Location: camping near the biggest power-up
|
|
Right, well, I think it's time to stop using that function. I have a pretty good idea of what it's giving you, and I'm pretty sure that's not what you're truly after.
I think it's only going to give you numbers between 0-90 degrees, if you're lucky it'll give you 0-180. Either way, you haven't posted negative values, or values that could somehow be interpreted as negative.
The next test should be to try multiple wrecks in the same direction, but at different distances away.
_________________
Nephylim wrote: But, an FA army in an FA environment just looks... right. Does anyone know how to use air transports? I cant get them to pick up troops.
|
|
| Top |
|
 |
|
Domino
|
Posted: 01 Feb, 2012
|
|
Joined: 26 Feb, 2009 Posts: 2996
|
Hi, Code: INFO: YawDegrees 23.58550453186 INFO: YawRadians 0.41164472699165
INFO: YawDegrees 39.198413848877 INFO: YawRadians 0.6841413974762
INFO: YawDegrees 54.782482147217 INFO: YawRadians 0.95613473653793 you are correct there are no negative numbers, ive been using Code: local dirvector = util.GetDirectionVector(wreck:GetPosition(),self:GetPosition()) if the number returned is negative go left -degrees else go right degrees, i know its wrong, however its an indicator on which direction to go... the numbers above are.. acu facing south, 3x target on same line to the east, the acu turns to the west (oposite direction) .. looks like you are correct, it should really return the same degree or near enough the same as the targets are in a lateral line to the east.. :/ i really have no idea what to do :/ ive been using this for referrance http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/index.htmpercificly the 3d vector part.
_________________ Domino. ______________
|
|
| Top |
|
 |
|
BulletMagnet
|
Posted: 01 Feb, 2012
|
|
Joined: 05 Oct, 2007 Posts: 16424 Location: camping near the biggest power-up
|
|
Throw my code in, and print what it calculates.
Anyway, it's 3:15AM here. You're going to have to survive on your own for a few hours. ;P
_________________
Nephylim wrote: But, an FA army in an FA environment just looks... right. Does anyone know how to use air transports? I cant get them to pick up troops.
|
|
| Top |
|
 |
 |
 |
|