noocrypte.net http://noozone.free.fr/noocrypte/ |
|
Unity 3D camera volante http://noozone.free.fr/noocrypte/viewtopic.php?f=47&t=4592 |
Page 1 sur 1 |
Auteur: | yann.minh [ Sam Nov 19, 2011 4:17 pm ] |
Sujet du message: | Unity 3D camera volante |
UNITY 3D camera volante Voir cette page (c'est un script en C+) http://forum.unity3d.com/threads/5633-F ... ala-UT2004)-Solution nm8shun Flying Object (ala UT2004) Solution Posted: 09:26 PM 07-15-2007 Hi.... Thanks to all the helpful posts on my queries about this (special thanks to Targos, Eric5h5, and eloehfelm). I've used a bit of all of the suggestions to find a solution I'm happy with, so I thought I'd share it - in case someone needed the same. Steps: 1) Define an Input Element called UpDown. Be sure to set the Negative and Positive button to your liking (I used r and e, and left shift and left ctrl.) 2) Create a Camera and an Empty Game Object. 3) Parent the Camera to the Empty Game Object. 4) Apply the prebuilt Mouse Look (Script) to the Empty Game Object. 5) Apply a Box Collider to the Game Object. 6) Build a new script called "Thruster" 7) The script I used is as follows: Code: using UnityEngine; using System.Collections; public class Thruster : MonoBehaviour { // declare the variables public float Speed = 9; public float Drag = 20; public float DragNoMovement = 50; const float airDrag = 0F; void FixedUpdate () { // get the inputs float horizontal = Input.GetAxis ("Horizontal"); float vertical = Input.GetAxis ("Vertical"); float altitude = Input.GetAxis ("UpDown"); // check to see if the user is moving bool userMoved = Mathf.Abs (horizontal) > 0.1F || Mathf.Abs (vertical) > 0.1F || Mathf.Abs (altitude) > 0.1F; // determine the force vector float x = horizontal * Speed; float z = vertical * Speed; float y = altitude * Speed; rigidbody.AddRelativeForce (new Vector3 (x, y, z), ForceMode.VelocityChange); // apply the appropriate drag when moving if (userMoved) rigidbody.drag = Drag; else rigidbody.drag = DragNoMovement; } void Start () { if (rigidbody==null) gameObject.AddComponent ("Rigidbody"); // don't let the physics engine rotate the character rigidbody.freezeRotation = true; } } peptoabysmal Location California Posts 33 Posted: 06:48 PM 12-13-2007 @wadamw Thank you for posting this script. I use it all the time. I've added some functionality and thought I'd share. You need to create the object as specified above and then attach this separate script to the camera. It gives you a roll function using (in my case: keys q and e, you might prefer different keys) I originally called it "bank.js" for "banking" but decided "roll" was a more accurate term. Code: // needs to be attached to the camera and an input named "roll" must be set up
var speed = 100.0; function Update(){ var roll = Input.GetAxis("roll"); transform.Rotate(0,0,-roll * Time.deltaTime * speed); } |
Page 1 sur 1 | Heures au format UTC [ Heure d’été ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |