Hi i want that my ship rolles when i press "q" to left and on "e" to the right. Every rotation i tried didnt work. Here is an example of what i tried.
var speed = 200;
var acc = 60;
var acc2 = 160;
var mom = 0;
var momb = 0;
var movleft = 0;
var movright = 0;
var rotleft = 0;
var rotright = 0;
var besch = 1;
var beschr = 20;
var hyper = 2000;
var smooth = 2.0;
var tiltAngle = 30.0;
var rotateSpeed = 20.0;
function Update () {
if (mom < 0){
mom = 0;
}
if (Input.GetKey ("up") || Input.GetKey ("w")) {
if (mom <= speed){
mom = mom + besch;
if (mom > speed){
mom = speed;
}
}
} else {
if (mom >= 0){
mom = mom - besch;
} else {
mom = 0;
}
}
if (Input.GetKey ("down") || Input.GetKey ("s")) {
mom = mom - besch;
if (mom < 0){
mom = 0;
}
}
if (Input.GetKey ("left") || Input.GetKey ("a")) {
if (movleft <= acc){
movleft = movleft + besch;
if (movleft >= acc){
movleft = acc;
}
}
} else {
if (movleft > 0){
movleft = movleft - besch;
}
}
if (Input.GetKey ("right") || Input.GetKey ("d")) {
if (movright <= acc){
movright = movright + besch;
if (movright >= acc){
movright = acc;
}
}
} else {
if (movright > 0){
movright = movright - besch;
}
}
if (Input.GetKey ("e")) {
if (rotright <= acc2){
rotright = rotright + beschr;
if (rotright >= acc2){
rotright = acc2;
}
}
} else {
if (rotright > 0){
rotright = rotright - beschr;
}
}
if (Input.GetKey ("q")) {
if (rotleft <= acc2){
rotleft = rotleft + beschr;
}
} else {
if (rotleft > 0){
rotleft = rotleft - beschr;
}
}
if (Input.GetKey ("j")) {
speed = hyper;
besch = 10;
}
if (mom < 0){
mom = 0;
}
transform.Translate(0, 0, Time.deltaTime*mom);
transform.Translate(0, 0, -Time.deltaTime*momb);
transform.Translate(-Time.deltaTime*movleft, 0,0);
transform.Translate(Time.deltaTime*movright, 0, 0);
//transform.Rotate (0, 0, -Time.deltaTime*rotright);
//transform.Rotate (0, 0, Time.deltaTime*rotleft);
//transform.Rotate(Vector3(0, 0, 1), Time.deltaTime*rotleft);
//transform.Rotate(Vector3(0, 0, 1), -Time.deltaTime*rotright);
//var tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle;
var tiltAroundZ = Input.GetKey ("q") * 30;
//var target = Quaternion.Euler (0, tiltAroundX, 0);
transform.rotation = Quaternion.Slerp(transform.rotation, target,Time.deltaTime * smooth);
}
Are you trying to do a complete barrel roll? Or just a tilt?
– anon61907549