- Home /
Question by
ace2df · Mar 18, 2016 at 12:43 PM ·
transformpositionbeginnermove an object
Moving object to object (with Bezier Curve) doesn't land on it
I'm using basically this: http://answers.unity3d.com/questions/12689/moving-an-object-along-a-bezier-curve.html
public GameObject hit_target;
private Vector2 move_to_target;
private Vector2 start_point;
private Vector2 end_point;
private float CurveX;
private float CurveY;
private float BezierTime;
private bool isFinished = false;
public int curveAddX = 6;
public int curveAddY = 6;
void Start () {
start_point = transform.position;
move_to_target = hit_target.transform.position;
}
void FixedUpdate () {
if (isFinished)
Destroy (this);
BezierTime = BezierTime + Time.deltaTime;
CurveX = (((1-BezierTime)*(1-BezierTime)) * start_point.x) + (2 * BezierTime * (1 - BezierTime) * curveAddX) + ((BezierTime * BezierTime) * move_to_target.x);
CurveY = (((1-BezierTime)*(1-BezierTime)) * start_point.y) + (2 * BezierTime * (1 - BezierTime) * curveAddY) + ((BezierTime * BezierTime) * move_to_target.y);
end_point = new Vector2 (CurveX, CurveY);
transform.position = end_point;
if (BezierTime >= 1)
{
isFinished = true;
}
}
But the end result is ending like this:
Where the in the maths should I change to get this to work? I've tried messing stuff around but still nothing. There is no middle point with the curve just object a and b.
ss2016-03-17at034642.png
(470 B)
Comment
Your answer
Follow this Question
Related Questions
How can I have 2 transforms have the same position and rotation 0 Answers
Moving child and parent 1 Answer
Move Overlapbox/GameObject depending on Parent 2 Answers
How to change position after some reference. 0 Answers
setting transform physics2d issue 0 Answers