how to add Flight to third person player?
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)
Answer by Cuttlas-U · Apr 07, 2017 at 09:17 AM
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);
}
}
Your answer
Follow this Question
Related Questions
Invector Multiplayer Photon 0 Answers
Third person game hit a ball 0 Answers
unity Third person uwp 0 Answers
Camera rotate X degree based on player rotate 0 Answers
CAn soem one give me Sphere script to move in third person 0 Answers