Question is off-topic or not relevant
Best way to move up and down character
My character moves forward back left and right with "wasd keys" but i want to move up and down like bee or something like that with "q and e" keys. What is the best way to this any idea?
This is asked way too often, there are hundreds of posts about that all around the internet. Also, UnityAnswers is not for this kind of questions. Take a look at the FAQ please.
Have a nice day.
PS: If you can move your character around the x and z axis already, then what's the problem with doing it for the y axis?
because i have this code and it is not working in unity 5
if (isUnderwater==true && Input.Get$$anonymous$$ey($$anonymous$$eyCode.E))
{
constantForce.relativeForce = Vector3 (0,-200,0);
}
else
{
constantForce.relativeForce = Vector3 (0,0,0);
}
if (isUnderwater==true && Input.Get$$anonymous$$ey($$anonymous$$eyCode.Q))
{
constantForce.relativeForce = Vector3 (0,200,0);
}
else
{
constantForce.relativeForce = Vector3 (0,0,0);
}
This is just a matter of simple logic, if you can already successfully move at the x and z axis, then y is not a problem. Just do it the same way you do it with x but just use y.
"This is not working" is probably the most non-specific statement one can say. ;) I suggest you stop doing this at the moment, and look at the different ways how a character can be presented in game and moved. Physics based, only changing position over time, a mixture of both, etc.
PS: Copying your code snippet and including it in a new script, works perfectly fine with me. I just removed the bool part because it's unneccesary for testing. Since you didn't give any info on "what happens" when it's "not working", I can't help you with that.
Answer by ForeignGod · Jan 15, 2016 at 08:11 AM
Depending on how you would like your movement to work you could use something like Rigidbody.Addforce or Transform.Translate
Simply input your Y axis instead of using X and Z values.
I take it that you know how to make use of this. If not, notify me and I can help with your script.
EDIT: Took my time and created this. Not very advanced and easy to customize.
import UnityEngine;
var character : Rigidbody;
var thrust : float;
// Use this for initialization
function Start () {
character = GetComponent.<Rigidbody>();
}
// Update is called once per frame
function Update () {
if (Input.GetKey(KeyCode.Q)){
character.AddForce(Vector3.up * thrust);
}
if (Input.GetKey(KeyCode.E)){
character.AddForce(Vector3.down * thrust);
}
}
http://docs.unity3d.com/ScriptReference/Rigidbody.AddForce.html http://docs.unity3d.com/ScriptReference/Transform.Translate.html
its good and nice thank you very much but is it possible without rigidbody do you think?
Yes that is possible, I still recommend doing this with a Rigidbody though.
import UnityEngine;
var character : Transform;
var thrust : float;
// Use this for initialization
function Start () {
character = GetComponent.<Transform>();
}
// Update is called once per frame
function Update () {
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.Q)){
character.Translate(Vector3.up * Time.deltaTime * thrust);
}
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.E)){
character.Translate(Vector3.down * Time.deltaTime * thrust);
}
}
Please stop posting to this question. It is closed for being off-topic. Unity Answers is not for discussions and how-to-gameplay questions.
If you want to further assist the OP, you can go to Unity Forums and do it there.
Answer by DCordoba · Jan 15, 2016 at 08:17 AM
Depends of the type of character. Usually for high speed characters, like dragons, high speed birds etc, to cant go backwards, has a key for throttle/aceleration (like space, or numbers to specific speed), and other for airbrakes/desaceleration (shift, or number 0, or backspace do decrease numbers) and the W/A/S/D for up/dow, left/right.
On slow speed characters, like insects or helicopters, that can fly backwards, usually are assigned the key arrows to up/down, but not is a criteria. Some games, (like novalogic f-22) combine throttle acceleration with arrows inverse (i.e. arrow up for tilt down), leaving W/A/S/D for other functions, like team orders (W), or auto-pilot(A).
All the helicopters of battlefield saga have the W/A/S/D to manage the rotors (horizontal rotation, and up/down), and the mouse to unbalance the main rotor (forward/backward and left/right), as secondary option usually uses the arrows to unbalance the main rotor.
The helicopters of GTA saga (more simplest aerodynamic simulation), have the W/A/S/D to unbalance the main rotor, and the space to up/down, if you release the space the rotor reduces speed and the helicopter starts going down, if maintain pressed the space, increment altitude until reaches a maximum. hope this helps, and forgive my bad english.
$$anonymous$$y god, please format your texts. At least use line breaks and paragraphes. This is just one long strip of text and a pain in the eyes to read. ;)
what about now? subdivided into four paragraphs, the first for the characters (and machines) with high speed, the other three, more extensive because it seems what is planning to do, to characters with low speed.