using System.Collections; using System.Collections.Generic; using UnityEngine; public class DroneMo

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DroneMovementScript : MonoBehaviour
{

Rigidbody ourDrone;

void Awake(){
ourDrone = GetComponent();
}

void FixedUpdate()
{
MovementUpDown();
MovementForward();
Rotation();

ourDrone.AddRelativeForce(Vector3.up * upForce);
ourDrone.rotation = Quaternion.Euler(
new Vector3(tiltAmountForward, currentYRotation, ourDrone.rotation.z)
);
}

public float upForce;
void MovementUpDown()
{
if (Input.GetKey(KeyCode.I))
{
upForce = 450;
}
else if (Input.GetKey(KeyCode.K))
{
upForce = -200;
}
else if (!Input.GetKey(KeyCode.I) && !Input.GetKey(KeyCode.K))
{
upForce = 98.1f;
}
}

private float movementForwardSpeed = 500.0f;
private float tiltAmountForward = 0;
private float titltVelocityForward;
void MovementForward()
{
if(Input.GetAxis(“Vertical”) != 0) {
ourDrone.AddRelativeForce(Vector3.forward * Input.GetAxis(“Vertical”) * movementForwardSpeed);
tiltAmountForward = Mathf.SmoothDamp(tiltAmountForward, 20 * Input.GetAxis(“Vertical”), ref titltVelocityForward, 0.1f);
}
}

private float wantedYRotation;
private float currentYRotation;
private float rotateAmoutByKeys = 2.5f;
private float rotationYVelocity;
void Rotation()
{
if (Input.GetKey(KeyCode.J))
{
wantedYRotation -= rotationAmoutByKeys;
}
if (Input.GetKey(KeyCode.K))
{
wantedYRotation += rotationAmoutByKeys;
}

currentYRotation = Mathf.SmoothDamp(currentYRotation, wantedYRotation, res rotationYVelocity, 0.25f);
}

}

My software is above. Who can help me solve my problem.

7042633–834994–DroneMovementScript.cs (1.92 KB)

Please use code-tags and if you have a problem then say what the problem actually is rather than simply dumping code. Also, use the title to provide a quick problem summary.

Also, if this relates to a specific problem (such as Physics) then please post in the appropriate forum.

Thanks.

Nobody here is a mind-reader. Let me help you with how to actually use the forum properly:

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

How to understand compiler and other errors and even fix them yourself:

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: Using code tags properly

Also, consider this:

1 Like