Author |
Message |
Cadwaller
Joined: Wed Jun 03, 2009 1:12 am Posts: 93
|
Help with rotational motion coordinate equation (not for cc)
Hi, I'm making a game with a fairly primitive language and I need to make an equation for determining the x and y changes in the position of an attached object based off of the rotation of a parent object. (Imagine a person spinning and throwing a shotput, with the person as the parent object and the shotput as attached object.) Just to clarify, the parent object is not moving, only rotating, while the center of the attached object is moving around it. Things I would like to use in solving this would be the radius, coordinates, and trigonometric functions.
Thanks for going to the trouble of reading this lengthy post.
|
Sat Nov 14, 2009 6:57 am |
|
|
Duh102
happy carebear mom
Joined: Tue Mar 04, 2008 1:40 am Posts: 7096 Location: b8bbd5
|
Re: Help with rotational motion coordinate equation (not for cc)
Child.X = parent.X + (Cos(angle) * radius) Child.Y = parent.Y + (Sin(angle) * radius) The sin/cos might be switched, but I think that's right...
|
Sat Nov 14, 2009 7:42 am |
|
|
Cadwaller
Joined: Wed Jun 03, 2009 1:12 am Posts: 93
|
Re: Help with rotational motion coordinate equation (not for cc)
Thanks! Trying it out right away
|
Sat Nov 14, 2009 10:40 am |
|
|
Cadwaller
Joined: Wed Jun 03, 2009 1:12 am Posts: 93
|
Re: Help with rotational motion coordinate equation (not for cc)
This worked very well in most ways, but when I tested it out the child object slowly spiraled into the parent through multiple rotations. Do you know why this might be?
|
Sat Nov 14, 2009 10:50 am |
|
|
411570N3
Joined: Wed Jan 07, 2009 10:26 am Posts: 4074 Location: That quaint little British colony down south
|
Re: Help with rotational motion coordinate equation (not for cc)
Try switching cos and sin, like he suggested.
|
Sat Nov 14, 2009 11:09 am |
|
|
weasel
Joined: Wed Sep 16, 2009 6:22 pm Posts: 491 Location: Victoria, BC
|
Re: Help with rotational motion coordinate equation (not for cc)
Also, is it in flash/as2/as3?
If so you can use the globalToLocal and localToGlobal functions to get the relative coordinates, and it bypasses the fancy maths thus saving you some CPU overhead (which probably won't be a big deal for you, but just in case).
|
Sat Nov 14, 2009 11:44 am |
|
|
Duh102
happy carebear mom
Joined: Tue Mar 04, 2008 1:40 am Posts: 7096 Location: b8bbd5
|
Re: Help with rotational motion coordinate equation (not for cc)
Cadwaller wrote: Do you know why this might be? The radius is decreasing somewhere along the way. Probably should take a look at anything that uses it. I could be wrong and it could be something to do with your language's handling of sin/cos, but that seems unlikely. What language are you using anyway?
|
Sat Nov 14, 2009 2:46 pm |
|
|
Cadwaller
Joined: Wed Jun 03, 2009 1:12 am Posts: 93
|
Re: Help with rotational motion coordinate equation (not for cc)
Hmm... I'm using basic so I can't use weasel's idea, is there any way to code an object to not be allowed to come within a set distance of another object? oh, also, I tried switching the sin and cos.
|
Sat Nov 14, 2009 8:36 pm |
|
|
Cadwaller
Joined: Wed Jun 03, 2009 1:12 am Posts: 93
|
Re: Help with rotational motion coordinate equation (not for cc)
Great! I found I really simple, embarrassing solution to the problem. I should have made the radius a fixed value outside of the loop so that it didn't change with rotation. Thanks for everyone's help!
|
Sat Nov 14, 2009 8:54 pm |
|
|
weasel
Joined: Wed Sep 16, 2009 6:22 pm Posts: 491 Location: Victoria, BC
|
Re: Help with rotational motion coordinate equation (not for cc)
Cadwaller wrote: Hmm... I'm using basic so I can't use weasel's idea, is there any way to code an object to not be allowed to come within a set distance of another object? oh, also, I tried switching the sin and cos. distance = 10 if (object1.x - object2.x < 10) object1.x = object2-10; very basic clunky way to do it, but very simple. You might want to do some basic trig to get a round radius.
|
Sun Nov 15, 2009 12:03 am |
|
|
|