# Forum

CS2D Scripts Get X and Y based on rotation

# Get X and Y based on rotation

6 replies
Goto Page
1
08.12.19 07:14:04 am
Goo
User
Offline
I have (pixel) X and Y.
I also have a rotation.

I want the X and Y to point at the object.

This might explain it better, it's hard for me to explain.
08.12.19 08:20:49 am
User
Offline
Okay. How can a circle can have a rotation?
And if your result is really this rectangle I dont get how you came to the solution.

So you have a starting point with X,Y and rot? Then you want to see the next objects this point is "watching at"?

I would increment the view distance and check everytime if something is on the way.
Once you hit it you do know c and all angles in my triangle. Then you can get whatever you want.
edited 1×, last 08.12.19 09:16:26 am
Share time limited free games here
08.12.19 10:04:56 am
SQ
Moderator
Offline
Probably he means that:

He has Object A and Object B
He wants to set rotation of Object A so it is looking at Object B

Code:
1
rotation = Atan2(objectA.y - objectB.y, objectA.x - objectB.b)

After you get rotation, you can push your old position towards the new one.
Code:
1
2
ObjectA.x + cos(rotation) * distance
ObjectA.y + sin(rotation) * distance
edited 2×, last 08.12.19 11:28:32 am
08.12.19 02:19:36 pm
Goo
User
Offline
@ SQ: Thank you! It works like a charm
09.12.19 01:52:26 pm
Gaios
Security Supporter
Offline
09.12.19 02:11:51 pm
Goo
User
Offline
@ Gaios: what?

This isn't the same formula, is it?
09.12.19 03:43:57 pm
SQ
Moderator
Offline
@ Goo: It IS pretty much the same thing. Basic trigonometry.
1
﻿