Poster un nouveau sujet Répondre au sujet  [ 1 message ] 
Auteur Message
 Sujet du message: Unity 3D camera volante
UNREAD_POSTPosté: Sam Nov 19, 2011 4:17 pm 
Avatar de l’utilisateur
Inscription: Mar Jan 09, 2007 3:21 am
Messages: 1164
UNITY 3D camera volante

Voir cette page (c'est un script en C+) ... ala-UT2004)-Solution

Flying Object (ala UT2004) Solution
Posted: 09:26 PM 07-15-2007

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.

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:

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;
         rigidbody.drag = DragNoMovement;
   void Start () {
      if (rigidbody==null)
         gameObject.AddComponent ("Rigidbody");

      // don't let the physics engine rotate the character
      rigidbody.freezeRotation = true;


Posted: 06:48 PM 12-13-2007
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.

// 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);

 Hors ligne

Afficher les messages postés depuis:  Trier par  

Poster un nouveau sujet Répondre au sujet  [ 1 message ] 

Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 1 invité


Haut Vous ne pouvez pas poster de nouveaux sujets
Vous ne pouvez pas répondre aux sujets
Vous ne pouvez pas éditer vos messages
Vous ne pouvez pas supprimer vos messages
Aller à:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Traduction par:
Dizayn Ercan Koc