- Home /
Question by
seanoh1989 · Apr 08, 2019 at 08:24 AM ·
velocitymathcircle
Launching object in circular motion
I have an object that's rotating around a point (x,y) using
transform.RotateAround(CurrentSun.transform.localPosition, Vector3.forward, speed * Time.deltaTime);
I want this object to launch out to a vector with a constant speed.
This looks like basic math, but I can't figure out what to search for (keyword/API).
When I push, say Space, I will know the radius of the circle, and I will know the speed (as it's constant), and I will know the current transform.position of the object rotating around.
Can someone help me out?
vector.png
(28.1 kB)
Comment
Answer by xxmariofer · Apr 08, 2019 at 09:03 AM
you can get the vector form the center of the sphere to the point using B - A and just get the normal of that vector as force
example
Vector3 direction = transform.position - CurrentSun.transform.localPosition;
Vector3 normal = new Vector3(direction.y, -direction.x):// or -y,x
then just add force in that direction
GetComponent<Rigidbody>().AddForce(normal);