- Home /
Question is off-topic or not relevant
Making character to fly
I have a little problem with my character to fly. I am looking for a way to have my character to fly when I hold down a button. I have the character movement already but now, i am look for a way to have my character to fly. I looked for answers on this site relating to flying but they did not seem to work on my project. Could someone please show some sample code to make my character fly?
Hi Slidecoast,
By using spacebar we will make jump. I think ur missing some clarity. please update ur question.
http://www.packtpub.com/article/unity3-building-rocket-launcher this link is may be help for u.
Well the only way I can think of is add a force in the y direction whenever u press this key.. Try it and show us what you have done so far so we could help you more.
Sorry, but your question is not suitable for Unity Answers, and this is not the place to ask for code. Please use the Unity Forum for discussions such as "How to ...". Unity Answers is here to help you solve any specific problems you have.
Answer by aldonaletto · May 13, 2013 at 09:25 AM
Well, this depends on your movement code. If it's a custom script, edit your answer and post it - it's impossible to help you without knowing your code. If you're using the First Person Controller, however, you must use specific functions available in the complicated CharacterMotor.js script. A simple way to implement a kind of jet-pack feature is to add the script below to the First Person Controller:
var cMotor: CharacterMotor; // reference to the CharacterMotor script
function Start(){ // get the CharacterMotor script at Start:
cMotor = GetComponent(CharacterMotor);
}
function Update(){ // move player upwards while F is pressed
if (Input.GetKey("f")){
cMotor.SetVelocity(Vector3.up*1.5);
}
}
// This do-nothing function is included just to avoid error messages
// because SetVelocity tries to call it
function OnExternalVelocity(){
}
Do you know any code that can make a character to glide?
To glide would be like flying but without thrust I would think.
So the logic remains the same except that you only gain speed when going down.
It may a little tricky since you would have to check angle between the player and the Vector3.up to see that when the dot is 0 the character is gliding but when the dot product is negative degrees then you gain speed and this gain increased as your dot gets closer to -1 which means you are head down.
If the dot is positive, then you are going up but you are also losing speed.
That is what I would start with. But I have never done that nor have I ever glided.
How can I detect when my character is jumping or falling? If I can detect jump collision, then I can try to make my character to glide. Could you show some sample code in relation to how to make the character to glide? or to make a character slow