Hey
I’v been working on top down 2D RTS and found a great youtube tutorial for 3D RTS detailing movement selection and movement.
The selection script I adapted fine, but the movement script has me stumped and don’t have a lot of idea on how to adapt it to an x-y plane, rather then x-z. Any help would be greatly appreciated.
Here’s the video:
Here’s the script he’s written in the tutorial:
Code
private void UpdateMove()
{
if (movetoDest != Vector3.zero && transform.position != movetoDest)
{
Vector2 direction = (movetoDest - transform.position).normalized;
transform.GetComponent<Rigidbody>().velocity = direction * speed;
if (Vector2.Distance(transform.position, movetoDest) < stopDistanceOffset)
movetoDest = Vector2.zero;
}
else
transform.GetComponent<Rigidbody>().velocity = Vector2.zero;
}
}
and here:
private void UpdateMove()
{
if (movetoDest != Vector3.zero && transform.position != movetoDest)
{
Vector3 direction = (movetoDest - transform.position).normalized;
transform.GetComponent<Rigidbody>().velocity = direction * speed;
if (Vector3.Distance(transform.position, movetoDest) < stopDistanceOffset)
movetoDest = Vector3.zero;
}
else
transform.GetComponent<Rigidbody>().velocity = Vector3.zero;
}
}
Keep in mind some of this code may appear different due to my adaption of it
Please let me know if this is too vague and how I can help you help me! this is my first post so I’m not to sure on some of the etiquette around here