Make a rotating line(capsule) always look at a sphere on the y-axis. (C#)

Hi fellow Unity-User :smile:

I’m having a Problem with a task.

I have two points(Spheres) with a line(capsule) and another point with a line.
I called them PointA, PointB, PointC, Line and Line 2.
Line goes through PointA and PointB and PointB and the first Line are rotating around PointA.
Now I want Line2 to rotate with PointB around PointA… but I also want Line2 to never leave the not moving PointC.

Do you guys have any ideas ?
If something isn’t clear I’ll try to do my best to explain it to you :smile:

Thanks for help in advance

Stakior

I hope you can see the pic :smile:

PointC,Line2,PointB,Line and PontA (from left to right)

A picture of this problem would be great, as yes, it isn’t quite clear enough for me… :smile:

How can I get a pic in here ? .-.

Oh dear… :smile:

Anyway, when posting, use the “upload a file” button, select your picture, and once it uploads, click either “thumbnail” or “full image” on the upload thing at the bottom of your posting box, and it should appear where your text cursor is in the text area.

I think I did it :smile:

I don’t see anything… :smile:

For real ? I edited my thread and now it’s at the top .-.

Oh, forgot to check first post! godzilla-facepalm
This is definitely confusing to do though…

What you seem to be trying to do is rotate one point, and have all the others, along with the lines, go round that point and Point C, am I correct? :eyes:

Oh wait!

I realized something: try using transform.RotateAround(point, angle) with the moving points, and transform.LookAt(point) to have the point’s line still point at point C. this should work with both lines.

At least that is how I think it would work… :smile:

I tried transform.LookAt but I cant get Line2 to look at PointC all the time .-.

and than I Need to change it to look at it with its y-axis too .-.

Ok…

Where is line2 cast from? :eyes: I know Line1 is cast in point A.

And what do you mean by “look at it with the Y-axis too?” :smile: If you mean facing the Y axis towards Point C, I am having the same problem too, but in my case, it’s so my characters face feet-first towards a distant planet… :wink:

Do you mean the middle of the “Line” cuz like I said it’s just a capsule with a scale of (0.1,9999,0.1) :smile:

I you mean the middle of it, it’s in PointB (the rotating one)

Well, then we are kinda in the same boat :smile: Damn .-.

Since my answer is somewhat solved in my support thread, see if the C# code example there helps:

from my skim-read, I am thinking it gets the object rotation, and faces it down toward the world origin. (in your case, point C)

I don’t understand it .-.

Ok… I just got my up vectors pointing correctly.

basically, have your sphere point like this (Note that I ripped this straight out of my code, so it’s in JS):

gravityVector = <the point you want to point to> - enemy.transform.position;
        <object to point with>.transform.up = -gravityVector;

If the object ends up pointing away from it instead though, remove the negative operator on the second line. (I had to leave it in, as my characters heads were pointing towards the origin! :smile:)

Still doesn’t work .-. I think I can’t figure out how to use this code ._.

What’s up with the gravityVector ? it doesn’t excist in C# .-.

Where’s your code? I can help better if you post it. :slight_smile: