View unanswered posts | View active topics It is currently Fri Dec 27, 2024 7:47 am



Reply to topic  [ 10 posts ] 
 Help with rotational motion coordinate equation (not for cc) 
Author Message
User avatar

Joined: Wed Jun 03, 2009 1:12 am
Posts: 93
Reply with quote
Post 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
Profile
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post 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
Profile
User avatar

Joined: Wed Jun 03, 2009 1:12 am
Posts: 93
Reply with quote
Post Re: Help with rotational motion coordinate equation (not for cc)
Thanks! Trying it out right away :)


Sat Nov 14, 2009 10:40 am
Profile
User avatar

Joined: Wed Jun 03, 2009 1:12 am
Posts: 93
Reply with quote
Post 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
Profile
User avatar

Joined: Wed Jan 07, 2009 10:26 am
Posts: 4074
Location: That quaint little British colony down south
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Wed Sep 16, 2009 6:22 pm
Posts: 491
Location: Victoria, BC
Reply with quote
Post 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
Profile ICQ YIM WWW
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post 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
Profile
User avatar

Joined: Wed Jun 03, 2009 1:12 am
Posts: 93
Reply with quote
Post 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
Profile
User avatar

Joined: Wed Jun 03, 2009 1:12 am
Posts: 93
Reply with quote
Post 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
Profile
User avatar

Joined: Wed Sep 16, 2009 6:22 pm
Posts: 491
Location: Victoria, BC
Reply with quote
Post 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
Profile ICQ YIM WWW
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.136s | 13 Queries | GZIP : Off ]