This question was
closed Apr 15, 2021 at 09:26 AM by
Pitak_ for the following reason:
Newer mind i fixed it.
Question by
Pitak_ · Apr 14, 2021 at 10:42 AM ·
movementscripting beginnerplane
Why does it starts going backwards.
Well I was making a game and i wrote a script for it and you can add trust on motors by pressing x and for some reason when the trust is on 57 or less it starts going backwards. Could someone explain me why?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movemento : MonoBehaviour
{
public float agility = 10f;
public float Engines= 120f;
public float horizontalSpeed = 1f;
public float verticalSpeed = 1f;
public float isengon = 1f;
public float speed = 0f;
// Start is called before the first frame update
void Start()
{
Application.targetFrameRate = 60;
}
// Update is called once per frame
void Update()
{
if (Input.GetKey (KeyCode.Q)) {
transform.Rotate(Vector3.forward * agility * Time.deltaTime);
}
if (Input.GetKey (KeyCode.E)) {
transform.Rotate(Vector3.back * agility * Time.deltaTime);
}
if (Input.GetKey (KeyCode.A)) {
transform.Rotate(Vector3.down * agility * Time.deltaTime);
}
if (Input.GetKey (KeyCode.D)) {
transform.Rotate(Vector3.up * agility * Time.deltaTime);
}
if (Input.GetKey (KeyCode.W)) {
transform.Rotate(Vector3.right * agility * Time.deltaTime);
}
if (Input.GetKey (KeyCode.S)) {
transform.Rotate(Vector3.left * agility * Time.deltaTime);
}
if (Input.GetKey (KeyCode.UpArrow)) {
transform.Translate (0f, 0f, 3f);
}
if (Input.GetKey (KeyCode.DownArrow)) {
transform.Translate (0f, 0f, -1.5f);
}
if (Input.GetKey (KeyCode.Space)){
isengon = 1f;
}
if (Input.GetKey (KeyCode.LeftControl)){
if (60 >= Engines){
if (-60 <= Engines){
isengon = 0f;
}
}
}
if (Input.GetKey (KeyCode.X)){
if (Engines <= 400){
Engines = Engines+1f;
IEnumerator MyCoroutine(float someParameter)
{
yield return new WaitForSeconds(0.5f);
}
}
}
if (Input.GetKey (KeyCode.C)) {
Engines = Engines-1f;
IEnumerator MyCoroutine(float someParameter)
{
yield return new WaitForSeconds(0.5f);
}
}
if (isengon == 1f){
speed = (0.05f*Engines);
transform.Translate (0f, 0f, speed);
IEnumerator MyCoroutine(float someParameter)
{
transform.position = Vector3.zero;
yield return new WaitForSeconds(1f);
}
}
}
}
Comment