Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

Add force up up in local space?

$
0
0
Hi. I've recently started to make my own flying game. So at first things went smoothly, as I can control the plane in terms of pitch, yaw and roll. However, things went awry when I tried to simulate lift. The intention is that lift should give the plane thrust in its own relative Y coordinate, as it is in real life. However, for some reason, it makes the plane fly upwards in its global direction, which is just wrong. Any ideas? [Youtube Video][1] [1]: https://www.youtube.com/watch?v=tqXy498RjQ4&feature=youtu.be using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlanePhysics : MonoBehaviour { public float thrust; public Rigidbody rb; public float liftfactor; public float lift; public float PitchForce; public float YawForce; public float RollForce; float speed; void Start() { rb = GetComponent(); } void FixedUpdate() { rb.AddRelativeForce(Vector3.forward * thrust); rb.AddForce(Vector3.up * lift); float yaw = Input.GetAxis("Yaw"); rb.AddTorque(transform.up * YawForce * yaw); float roll = Input.GetAxis("Roll"); rb.AddTorque(transform.forward * RollForce * roll); float pitch = Input.GetAxis("Pitch"); rb.AddTorque(transform.right * PitchForce * pitch); } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>