The Daily Click ::. Forums ::. Klik Coding Help ::. Angle??
 

Post Reply  Post Oekaki 
 

Posted By Message

\/\/olf

Creative Genius

Registered
  06/08/2005
Points
  76

VIP Member
20th October, 2007 at 19:54:25 -

Here's an image. The stick figure represents the character or active object. Now, thinking that there's a vertical line across his torso, how do i find the angle between the arm and the line? perhaps, the image will explain better. 'x' is the angle i want to find. it would be best if i only have to use action point for it and not the hot spot. angle calculator?? advanced math??

http://img136.imageshack.us/img136/6800/anglequestionuj4.png

any help is always most appreciated.

Image Edited by the Author.

 
Image

www.OldMansTale.net
Sign the Petition! Go go Go!!

viva/volt

Awesome Sauce

Registered
  26/08/2006
Points
  1694

Game of the Week WinnerSilverNova MemberKlikCast StarVIP Member
21st October, 2007 at 03:00:45 -

You need an object that you set the the mouse's X and Y co-ordinates firstly, I'll call it MouseObject. This will calculate the angle in alterable value A of your character.

If X of MouseObject is Lower than X of Guy
---> Set alt value A to 180-ATan(((Y( "Guy" )-Y( "MouseObject" ))*1.0)/((X( "Guy" )-X( "MouseObject" ))*1.0))

If X of MouseObject is Greater than X of Guy
---> Set alt value A to 0-ATan(((Y( "Guy" )-Y( "MouseObject" ))*1.0)/((X( "Guy" )-X( "MouseObject" ))*1.0))

Well anyway that works for me.

 
Image
http://bfollington.tumblr.com

Klikmaster

Master of all things Klik

Registered
  08/07/2002
Points
  2599

Has Donated, Thank You!You've Been Circy'd!VIP MemberPS3 Owner
21st October, 2007 at 05:47:39 -

that is assuming he's using mouse for aiming of course...

 
n/a

\/\/olf

Creative Genius

Registered
  06/08/2005
Points
  76

VIP Member
21st October, 2007 at 19:30:53 -

hmmm, that definitely helps somewhat. im not using the mouse though. i take it that if i replace the mouse commands with the 'hand' (action point), it should work right? thanks btw

 
Image

www.OldMansTale.net
Sign the Petition! Go go Go!!

\/\/olf

Creative Genius

Registered
  06/08/2005
Points
  76

VIP Member
21st October, 2007 at 21:18:15 -

i tried your code, it doesnt seem to work for me. could you explain or draw out what you're doing exactly to get the angle? trig right?

 
Image

www.OldMansTale.net
Sign the Petition! Go go Go!!

viva/volt

Awesome Sauce

Registered
  26/08/2006
Points
  1694

Game of the Week WinnerSilverNova MemberKlikCast StarVIP Member
21st October, 2007 at 21:26:34 -

If your not using the mouse simply position the "MouseObject" using whatever movement or positioning code you like? That should work I think :S.

 
Image
http://bfollington.tumblr.com

\/\/olf

Creative Genius

Registered
  06/08/2005
Points
  76

VIP Member
21st October, 2007 at 21:35:25 -

its not. ill tell you what im doing. im trying to move a sword (rotate) when the hero moves his arm. this way i dont have to make animations for adding the sword. but the code you gave me, gives me answers in 0.0000 to 1.0000 degrees. or something a little more than that. so my sword just twitches :S the degrees should be more than 1 for it to move correctly :S could you tell me wt you are doing? do you have any idea how that could work?

 
Image

www.OldMansTale.net
Sign the Petition! Go go Go!!

\/\/olf

Creative Genius

Registered
  06/08/2005
Points
  76

VIP Member
21st October, 2007 at 21:38:00 -

oh n just for testing purposes, im moving a red box using keyboard around the hero and using the drawline object to see what the angle should look like.

 
Image

www.OldMansTale.net
Sign the Petition! Go go Go!!

\/\/olf

Creative Genius

Registered
  06/08/2005
Points
  76

VIP Member
21st October, 2007 at 21:58:20 -

ok, i got most of it working. i just had to mulitply the equation with 100 the only problem i have left now is that whenever i switch over from the positive to negative degrees (that you're equation gives me ), i get a jerk in the weapon for some reason. it goes back a few angles. so i cant really do a complete smooth 360 with it. and its very important that i do. do you know why that would be? btw, thanks a lot man. you're a genius perhaps, the problem with it for me is that you're equation is 180 degree based and i need 360 degrees. you convert the gradient between the points and convert it to degrees if im not mistaken, yes?

so is tehre a way to get it done for 360 degrees?

Image Edited by the Author.

 
Image

www.OldMansTale.net
Sign the Petition! Go go Go!!

Hernan



Registered
  04/03/2003
Points
  707

VIP Member
22nd October, 2007 at 10:06:37 -

It'd help if you study some goniometry >_>

The equation Ben gave you returns a value in degrees (if you always get a number that's a lot smaller, than it's probably radians... or you just did it wrong ) Looking at Ben's equation, it all seems fine. If you don't want negative values, just add +90 everywhere.

Also, it's not 180 based. That'd be very odd.

 
This space is for rent

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
22nd October, 2007 at 11:05:19 -

If i remember rightly, it returns Atan as a value in radians.
pi radians=180 degrees
i.e if you multiply your returned Atan value by 180/pi it should return the correct angle in degrees.

 
My signature is never too big!!!

\/\/olf

Creative Genius

Registered
  06/08/2005
Points
  76

VIP Member
22nd October, 2007 at 19:06:00 -

haha, thanks a lot Joe. That fixed everything. and lol, I suppose studying would help defnitely. before Benothy told me his equation, I was trying to do this by using triangles. Had very little success with that. Anyway, you two are definitely gonna credit if my game is ever finished thanks!

Image Edited by the Author.

 
Image

www.OldMansTale.net
Sign the Petition! Go go Go!!
   

Post Reply



 



Advertisement

Worth A Click