wing suit physics
Hi I'm fairly new to scripting and I'm wondering how i would achieve "wing suit" physics (3d), as in you gain speed by facing downwards (more than 20 degrees - max is 90 due to camera), lose speed slowly by flying straight, lose speed quickly by flying upwards (more than 20 degrees - max 90) and then when speed is at 0 gravity starts pulling the character down (just like how a glider works)? I found a link to this: http://docs.unity3d.com/ScriptReference/Rigidbody.AddRelativeForce.html and i think this is what i need but instead of a set speed it will obviously need to be increasing and decreasing the thrust of my character based on my cameras x axis rotation. I guess what i need to to check is weather or not the angles or greater than or less than the above angles then applying the right amount of thrust I just don't no how I go about doing this, anyway, any help will be appreciated :D
I've done some research and this is the code i have (far from finished) and i have some problems.... 1) I can only move along the x and z axis not y 2) Once i start moving in one direction I cant look somewhere else and start moving there, I have to look downwards to speed up (slightly facing the direction i want to go while looking down)
using UnityEngine;
using System.Collections;
public class SpeedUp : $$anonymous$$onoBehaviour {
public Transform target;
public float thrust;
public Rigidbody rb;
void Update() {
Vector3 targetDir = target.position - transform.position;
Vector3 forward = transform.forward;
float angle = Vector3.Angle(targetDir, forward);
if (angle < 5.0F)
rb.AddRelativeForce(Vector3.forward * thrust);
}
}
Answer by Zenvin · Jun 07, 2017 at 03:56 PM
To check the angle, you could use "transform.eulerAngles.x". So you can do something like this:
float speed = 10f;
void Update () {
float currX_Angle = transform.eulerAngles.x;
if (currX_Angle < 90 && currX_Angle > 20) {
speed = 15f;
}
if(currX_Angle <= 20 && speed > 0) {
speed -= 1f
}
}
}
Then you can add the force multiplied by the speed and any other factor to the object's rigidbody.
Your answer
Follow this Question
Related Questions
Gravity on a cube planet 1 Answer
Changing gravity direction of player, and view. 2 Answers
How to change player gravity in a 3d space? 1 Answer
Charcter physics and groundedness 0 Answers
Newtons Cradle Balls? 1 Answer