Hi so i am trying to add flight to my character but nothing works also i am using the free invector third person template for basic movement and i the only thing i can script is animations. and i want to use the space bar to activate flight and W,A,S and D to control the direction you go and when you let go of space bar you fall back down any suggestions
(plus i’m new to Unity)
hi
i think u can first disbale the gravity;
then u can add force to player base on what key u press ;
bool canflight = false;
public void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
GetComponent<Rigidbody>().useGravity = false;
canflight = true;
}
if (Input.GetKeyUp(KeyCode.Space))
{
GetComponent<Rigidbody>().useGravity = true;
canflight = false;
}
if ( canflight)
{
if (Input.GetKeyDown(KeyCode.W))
GetComponent<Rigidbody>().AddForce(Vector3.up);
if (Input.GetKeyDown(KeyCode.D))
GetComponent<Rigidbody>().AddForce(Vector3.right);
if (Input.GetKeyDown(KeyCode.A))
GetComponent<Rigidbody>().AddForce(Vector3.right);
if (Input.GetKeyDown(KeyCode.S))
GetComponent<Rigidbody>().AddForce(-Vector3.up);
}
}