Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Hello i am a begginer in unity can you please help me

Discussion in 'Getting Started' started by pixel008, Aug 24, 2022.

  1. pixel008

    pixel008

    Joined:
    Aug 24, 2022
    Posts:
    1
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class AirplaneController : MonoBehaviour {
    6.  
    7.     public float FlySpeed = 5;
    8.     public float YawAmount = 120;
    9.  
    10.     private float Yaw;
    11.  
    12.     // Update is called once per frame
    13.     void Update() {
    14.  
    15.         // move forward
    16.         transform.position += transform.forward * FlySpeed * Time.deltaTime;
    17.  
    18.         // inputs
    19.         float horizontalInput = Input.GetAxis("Horizontal");
    20.         float verticalInput = Input.GetAxis("Vertical");
    21.  
    22.         // yaw, pitch, roll
    23.         Yaw += horizontalInput * YawAmount * Time.deltaTime;
    24.         float pitch = Mathf.Lerp(0, 35, Mathf.Abs(verticalInput)) * Mathf.Sign(verticalInput);
    25.         float roll = Mathf.Lerp(0, 35, Mathf.Abs(horizontalInput)) * -Mathf.Sign(horizontalInput);
    26.  
    27.         // apply rotation
    28.         transform.localRotation = Quaternion.Euler(Vector3.up * Yaw + Vector3.right * pitch + Vector3.forward * roll);
    29.  
    30.     }
    31. }
     
    Last edited: Aug 25, 2022
  2. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    459
    It looks to me like you are moving the transform, and, in an update function. I could be wrong, but it seems that isnt going to consider the collision.

    You will want to look into moving a rigidbody, or character controller, and also, using fixed update for most of the management, other than input.
     
  3. RichAllen2023

    RichAllen2023

    Joined:
    Jul 19, 2016
    Posts:
    807
    Use CODE tags when displaying code please.