I have an object
and then it wants to move the semi-circle
how?
Example
move to A until B
A
B
But follow the line
sry my english bad…
Can somebody help me???
Thx
I have an object
and then it wants to move the semi-circle
how?
Example
move to A until B
A
B
But follow the line
sry my english bad…
Can somebody help me???
Thx
Note :This answer will suite for Arc Movements (not for semi-circle)
Hi ardy3344,
have you ever tried with lerp movement for objects. if you use lerp movements using Vector3.lerp it would be easy.
First you need find the distance between A and B and divide the distance by 2.here you’ll get half distance right ? . you can find the center point from here. add the half distance with A or minus from B.
After this process you’ll get the midpoint for A and B. now increase Y-axis for 5 units and consider it as midpoint.
now you want to use Vector3.Lerp for A to midpoint, then midpoint to B. and you can do movements with time in lerp.
1st movement :
Vector3.lerp(GameObject.Find(A).transform.position,midpoint.transform.position,time);
2nd movement :
Vector3.lerp(midpoint.transform.position,GameObject.Find(B).transform.position,time);
you have to increase time in loops. sure you’ll get good arc movements.
I gave you the procedure for doing it simply. you may code it now.
Just use Trig. Break out your highschool geomtry book :), you know you want to . . .
// between 0 and 2 Mathf.PI.
float mPosition = 0F;
float mRadius = 5F;
void Update () {
mPosition += .01F;
transform.position = new Vector3(Mathf.Sin(mPosition)*mRadius, 0, Mathf.Cos(mPosition)*mRadius);
}
Has anyone found the exact answer to this question? I am looking for something similar.
You need to discover the center between A and B. Let’s call this centerPosition. And your object be at A:
transform.RotateAround (centerPosition, Vector3(0,0,-1), 75*Time.deltaTime);
This will make the object do a circular movement. You will need to check if your object is already at B.
And know the B position is easy, is the same distance between A and the centerPosition.
I know that this is an old question but I was trying to accomplish a similar thing so I thought why not post my solution here. After looking this page (Transformations of Functions and their Graphs) I played a little bit with the half circle function and managed to create the following code which should give you what you want.
// Private Instance variables
private float speed;
private float counter;
private float length;
private float height;
private Vector3 startPosition;
private Vector3 currentPosition;
//
void Start()
{
startPosition = transform.position;
currentPosition = Vector3.zero;
speed = 1f;
counter = 0f;
length = 30f;
height = 30f;
}
//
void Update()
{
counter += speed * Time.deltaTime;
currentPosition.x = Mathf.Sin(counter) * (length / 2f);
currentPosition.y = Mathf.Sqrt((Mathf.Pow((length / 2f), 2f)) - Mathf.Pow(pos.x, 2f)) / ((length / 2f) / height);
transform.position = currentPosition + startPosition;
}