- Home /
2D Trajectory Curve,Display trajectory while dragging
Hey there folks,
I hoped someone could help me with my problem. I want to display a trajectory curve using a calculated vector2 value. I'm going to transfer this to mobile input but for now I'm using mouse input. If you click the following script will store the point in space of the player and creates a second transform position while the mouse pointer is down. My goal is to draw a trajectory where the player will land. I've already used the search function but i couldn't find anything that fits. PlayerController script see below:
public Rigidbody rb;
public bool point = false;
public bool pointdown = false;
public bool pointup = false;
public float speedset;
Vector3 pointdownvec;
Vector3 pointcurrvec;
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
}
void FixedUpdate ()
{
point = Input.GetButton("Fire1");
PointerDown();
pointdown = Input.GetMouseButtonDown(0);
Drag();
pointup = Input.GetMouseButtonUp(0);
PointerUp();
}
public void PointerUp ()
{
//add.velocity, Pointer ID 0
if (pointup)
{
rb.velocity = Drag() / -speedset;
}
}
public void PointerDown ()
{
//Kurve Laden; Pointer ID 2
if (point)
{
pointdownvec = Input.mousePosition;
}
}
public Vector2 Drag()
{
//Kurve
if (pointdown)
{
pointcurrvec = Input.mousePosition;
}
Vector2 velovec = pointdownvec - pointcurrvec;
Debug.Log(velovec);
return velovec;
}
void OnTriggerEnter(Collider other) //restarting game if fall off
{
if (other.CompareTag("Respawn"))
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
Answer by MattG54321 · Dec 29, 2017 at 03:28 PM
It wasn't that easy but with this YouTube tutorial I could solve it. Thank you very much!
Your answer
Follow this Question
Related Questions
2D Detect collisions of a 2D block only on left/right (not top/bottom) 0 Answers
[2D] Moving the player 1 tile at a time using rigidbody movement 0 Answers
Sprites not recognized as whole-spinning in different directions 0 Answers
How can I make an object stop all momentum and hold it's position in air? 1 Answer
Why didnt my Collider works? 0 Answers