Jump to content

Find harmony in two relative things

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Maurice_Z

Maurice_Z

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
At the very beginning I must warn you, that explaining the problem will be hard to me.
Now, that you've been warned I'll start with quick explanation:
When position is relative to angle and angle is relative to position, how can I find the "perfect point"?
Now to have an example. I have two points: A(Xa,Ya) and B(Xb,Yb), I also have angle between them which is stored in DIR.
Point A - Static, moves with mouse move
Point B - Relative to Angle between two points
DIR - Relative to position of point B
So in one step I want to calculate the perfect position of point B, so it won't have to reassign, without using loops with one, relatively short algorithm.
And now, because it might not be sufficent, I'll give you a real-life example:
I have a platformer I'm working on. There is a player, who is made out of 4 parts: Body with head, arm, and two legs. The last two are not important. What is important is the body. In this game you aim using mouse, and the arm with gun rotates accordingly. To add realism, I decided to make it so the body bends when looking down, and moves aside(? Bends up?) when looking up. But when the body rotates the point where arm connects with body moves also. Look at the picture:
Posted Image
See? When the angle between Point A and B changes (DIR), so does the poistion of point B, and furthermore because of that DIR changes again, and so on...
So how can I find the harmony between these points? How can I find the one and only right point? ^^
If you need, these are the formulas I use:
Point A - Static, its positions are Xa and Xb
DIR - It is atan2(Xa-Xb,Ya-Yb)
temp_atan=ATan2(-4,-5)  //It's just temporarty variable, to quicken the calculations)
Xb=x+5+Sin(temp_atan+dir/5)
Yb=y+8+Cos(temp_atan+dir/5)
X and Y are coordinates of the player object, temp_atan, is the angle between rotation axis/point of body and point where body and arm joins.
(These codes above might not be perfect, as I keep finding mistakes here and there, but in any case I think I'd be able to change the finishing algorithm)

I hope it is understandable. It was hellishly difficult for me to explain ^^;
Thanks in advance

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Let me see if I understand:

You want the body to tilt when you aim up/down. This changes where the arm is, requiring a correction of the arm so you are still aiming at the desired location.

Thinking of this in terms of vectors, you want to have two vectors determine the position of the arm/body, rather than a single vector for the arm which will determine the appearance when aiming, correct? If so, I should be able to construct the equations you need to render the arm/body correctly.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Maurice_Z

Maurice_Z

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts

WingedPanther said:

Let me see if I understand:

You want the body to tilt when you aim up/down. This changes where the arm is, requiring a correction of the arm so you are still aiming at the desired location.

I'm not sure ^^;. The body tilt is dependant of the Angle between Arm and Mouse. When body Tilts, the position of arm changes. When position of Arm is change, the angle between Arm and Mouse changes. So the body has to tilt again. So the position of arm has to change again. So the Angle changes again.

Either way, I don't need it anymore, as I managed to write alternate algorithm which works fine. If you want to bother though, then I'll be grateful, as I enjoy gaining new experiences :).

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
In the end, it will proably end up being a system of equations (with what I'm thinking). If you have a working solution, I'll probably consider it "mission accomplished"
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog