- Home /
Question by
Brandon_Lindberg · Apr 25 at 03:43 AM ·
line renderer
Get object to follow line render that can have trajectory manipulated
I’m working on a project based off of the old flash game Steambirds. I’m trying to make a similar movement mechanic to the one in the game, with the ability to manipulate the aircrafts trajectory and have it follow the projected line when a turn is started. I’ve looked into it a bit but I’m somewhat stumped on how to accomplish this. Any advice or suggestions on the best way to do this?
Comment
Answer by landings · Apr 25 at 07:03 AM
Look at this code. Not tested though.
class ChaseCursor : MonoBehaviour {
private Plane plane;
private Vector3 velocity;
void Start(){
plane = new Plane(Vector3.up, this.transform.position);
}
void FixedUpdate(){
if (!plane) return;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float enter;
if (plane.Raycast(ray, out enter))
{
Vector3 endPoint = ray.GetPoint(enter);
Vector3 thisToEndPoint = endPoint - this.transform.position;
Vector3 acceleration = thisToEndPoint * 0.1f;
velocity += acceleration * Time.deltaTime;
aircraft.transform.position += velocity * Time.deltaTime;
aircraft.transform.LookAt(endPoint);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613055803im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Best way to place a Line Renderer into scene... 1 Answer
Line Renderer does not work with orthographic camera? 2 Answers
LineRenderer crashes the Update function 0 Answers
Need help with linerender 1 Answer
LineRenderer acts strangely 0 Answers