Find angle to object relative to direction bot is facing?

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
noobbotter
Posts: 527
Joined: Fri Aug 31, 2012 1:15 pm

Find angle to object relative to direction bot is facing?

#1 Post by noobbotter »

I'm trying to figure out how to determine the angle to an object relative to the direction my character is facing. For example, if my character is looking Due East, and the object I want an angle of is due South, it should return 90 degrees. If I'm looking Southeast and the object is Northwest, it should return 180 degrees. I'm not sure how I would go about doing that. I'm doing this in a userfunction, just in case that makes a difference.

I'm sure it's something similar to this part of a post I found but have no idea how to implement it, or how to make it work according to the relative direction my character is facing.

angle = atan2(y2-y1, x2-x1)+(M_PI);


Thanks for any help you can provide with this.
User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Find angle to object relative to direction bot is facing

#2 Post by rock5 »

Little known fact, even by me, is that there is a 'angleDifference' function in the bot. Of course you need to know the angle to your target. Looking at how it's used in the bot, I think this should work.

Code: Select all

angleToTarget = math.atan2(target.Z - player.Z, target.X - player.X)
angleDiff = angleDifference(angleToTarget, player.Direction)
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan
noobbotter
Posts: 527
Joined: Fri Aug 31, 2012 1:15 pm

Re: Find angle to object relative to direction bot is facing

#3 Post by noobbotter »

Thanks Rock. I think it was the player.Direction that was throwing me off. I didn't realize that existed. I'll give it a try when I get home tonight. If this is in a userfunction, would I have to do any kind of include for the math library or anything like that?
User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Find angle to object relative to direction bot is facing

#4 Post by rock5 »

It's part of the bot. Nothing to include.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan
noobbotter
Posts: 527
Joined: Fri Aug 31, 2012 1:15 pm

Re: Find angle to object relative to direction bot is facing

#5 Post by noobbotter »

Thanks again, Rock. I implemented it and it worked great. I just had to then convert the resulting radians to degrees.

Actually I can probably skip that part if I can figure out the straight conversion of radians to the angles of a clock-type direction. I'm using the degree of the angle to tell me a relative direction such as 3 O'clock, or 6 O'clock. For example, 12:00 would include angles greater than 344 and less than 15.

6:00 (180 degrees) would include any angles between 164 and 195.

I am using the following function after I find the angle (degree variable) to give an audible cue as to a direction:

Code: Select all

function angle(degree)
	if degree > 14 and 45 > degree then
		RoMScript("PlaySoundByPath('Interface/AddOns/ingamefunctions/One.wav')");
	elseif degree > 44 and 75 > degree then
		RoMScript("PlaySoundByPath('Interface/AddOns/ingamefunctions/Two.wav')");
	elseif degree > 74 and 105 > degree then
		RoMScript("PlaySoundByPath('Interface/AddOns/ingamefunctions/Three.wav')");
	elseif degree > 104 and 135 > degree then
		RoMScript("PlaySoundByPath('Interface/AddOns/ingamefunctions/Four.wav')");
	elseif degree > 134 and 165 > degree then
		RoMScript("PlaySoundByPath('Interface/AddOns/ingamefunctions/Five.wav')");
	elseif degree > 164 and 195 > degree then
		RoMScript("PlaySoundByPath('Interface/AddOns/ingamefunctions/Six.wav')");
	elseif degree > 194 and 225 > degree then
		RoMScript("PlaySoundByPath('Interface/AddOns/ingamefunctions/Seven.wav')");
	elseif degree > 224 and 255 > degree then
		RoMScript("PlaySoundByPath('Interface/AddOns/ingamefunctions/Eight.wav')");
	elseif degree > 254 and 285 > degree then
		RoMScript("PlaySoundByPath('Interface/AddOns/ingamefunctions/Nine.wav')");
	elseif degree > 284 and 315 > degree then
		RoMScript("PlaySoundByPath('Interface/AddOns/ingamefunctions/Ten.wav')");
	elseif degree > 314 and 345 > degree then
		RoMScript("PlaySoundByPath('Interface/AddOns/ingamefunctions/Eleven.wav')");
	elseif degree > 344 or 15 > degree then
		RoMScript("PlaySoundByPath('Interface/AddOns/ingamefunctions/Twelve.wav')");
	end
end
With that, is there a way to include a variable inside those RoMScript("PlaySoundByPath functions? I have tried it like this and didn't seem to get it to take the variable (in this case, the variable is "myvariable" which would be text of "One" thru "Twelve" which I want to use to play the file "One.wav" or "Twelve.wav" depending on what the variable is):

Code: Select all

RoMScript("PlaySoundByPath('Interface/AddOns/ingamefunctions/"..myvariable..".wav')");
Is there a way to get that to work or does the internal ' marks mess that up? I guess either way, I would still need to go through all those "if" statements to determine what to set the variable to so it's wouldn't necessarily speed it up any unless maybe I used a table to store all that info in.

Thanks.
User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Find angle to object relative to direction bot is facing

#6 Post by rock5 »

Code: Select all

RoMScript("PlaySoundByPath('Interface/AddOns/ingamefunctions/"..myvariable..".wav')");
That looks ok. Make sure you spelt myvariable correctly. Try printing out myvariable just before that, to make sure it has the value you expect. Check in game for any error messages.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan
Post Reply