noocrypte.net
http://noozone.free.fr/noocrypte/

Unity-3D-NooGyroCamera-
http://noozone.free.fr/noocrypte/viewtopic.php?f=47&t=7224
Page 1 sur 1

Auteur:  yann.minh [ Dim Avr 28, 2013 8:54 pm ]
Sujet du message:  Unity-3D-NooGyroCamera-

Les différents scripts à mettre dans la caméra sphère du NøøMuseum


1- Gyro-MouseLook-YM-2-SpeedAdjust

Ajustement de la vitesse de rottation de la camera

Code:
/// MouseLook rotates the transform based on the mouse delta.
/// Minimum and Maximum values can be used to constrain the possible rotation

/// To make an FPS style character:
/// - Create a capsule.
/// - Add a rigid body to the capsule
/// - Add the MouseLook script to the capsule.
///   -> Set the mouse look to use LookX. (You want to only turn character but not tilt it)
/// - Add FPSWalker script to the capsule

/// - Create a camera. Make the camera a child of the capsule. Reset it's transform.
/// - Add a MouseLook script to the camera.
///   -> Set the mouse look to use LookY. (You want the camera to tilt up and down like a head. The character already turns.)

enum RotationAxesB2 { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
   
public var axes : RotationAxesB2 = RotationAxesB2.MouseXAndY;
public var SensibiliteX : float= Time.deltaTime*3;
public var SensibiliteY : float= Time.deltaTime*3;

public var minimumX : float= -360;
public var maximumX : float= 360;

public var  minimumY : float= -60;
public var maximumY : float= 60;

var rotationX : float= 0;
var rotationY : float = 0;

var originalRotation : Quaternion;

var RotationSliderValue : float = 2.0; static var volume : float;




// affiche un curseur permettant de multiplier la vitesse de rotation
function OnGUI () {
RotationSliderValue = GUI.HorizontalSlider (Rect (0, 100, 100, 20), RotationSliderValue, 0.0, 10.0);
GUI.Box(Rect(0,80,100,35),"Rotation");
// AudioListener.volume = RotationSliderValue/10;

Debug.Log(RotationSliderValue);
}


function Update ()
{

var sensitivityX = SensibiliteX*(RotationSliderValue/2);
var sensitivityY = SensibiliteY*(RotationSliderValue/2);

   if(!Screen.lockCursor){
      //return;
   }
   
   var yQuaternion : Quaternion;
   var xQuaternion : Quaternion;
   Debug.Log(xQuaternion);
   
   //Debug.Log(Inputs.GetAxis("Horizontal"));   

   //var seuil = 0.01;
   if(Mathf.Abs(Inputs.GetAxis("Horizontal")) < 0.2) return;
//   if(Inputs.GetAxis("Vertical") < seuil) return;
   
   
   
   if (axes == RotationAxesB2.MouseXAndY)
   {
      // Read the mouse input axis
      rotationX += Inputs.GetAxis("Horizontal") * sensitivityX;
      rotationY += Inputs.GetAxis("Vertical") * sensitivityY;

      rotationX = ClampAngle (rotationX, minimumX, maximumX);
      rotationY = ClampAngle (rotationY, minimumY, maximumY);
      
      xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
      yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
      
      transform.localRotation = originalRotation * xQuaternion * yQuaternion;
   }
   else if (axes == RotationAxesB2.MouseX)
   {
      rotationX += Inputs.GetAxis("Horizontal") * sensitivityX;
      rotationX = ClampAngle (rotationX, minimumX, maximumX);

      xQuaternion  = Quaternion.AngleAxis (rotationX, Vector3.up);
      transform.localRotation = originalRotation * xQuaternion;
   }
   else
   {
      rotationY += Inputs.GetAxis("Vertical") * sensitivityY;
      rotationY = ClampAngle (rotationY, minimumY, maximumY);

      yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
      transform.localRotation = originalRotation * yQuaternion;
   }
}
   
function Start ()
{
   // Make the rigid body not change rotation
   if (rigidbody){
      rigidbody.freezeRotation = true;
   }
   originalRotation = transform.localRotation;
}
   
static function ClampAngle ( angle : float,  min : float, max :  float) : float
{
   if (angle < -360)
      angle += 360;
   if (angle > 360)
      angle -= 360;
   return Mathf.Clamp (angle, min, max);
}

Auteur:  yann.minh [ Dim Avr 28, 2013 8:55 pm ]
Sujet du message:  Re: Unity-3D-NooGyroCamera-

Ajustement de la vitesse de deplacement de la camera


Code:
#pragma strict
#pragma implicit
#pragma downcast

public var Speed : float= Time.deltaTime*0.06;
var rotation=Vector3.zero;
var moveable=true;
var nr="";

var SpeedSliderValue : float = 2.0; static var volume : float;

// affiche un curseur permettant de multiplier la vitesse de deplacement
function OnGUI () {
SpeedSliderValue = GUI.HorizontalSlider (Rect (0, 55, 100, 20), SpeedSliderValue, 0.0, 10.0);
GUI.Box(Rect(0,35,100,35),"Speed");
// AudioListener.volume = SpeedSliderValue/10;

Debug.Log(SpeedSliderValue);
}

function Update () {
   if(moveable){         
      //------Deplace l'objet en avant et arriere en fonction de l'axe "Vertical" du gyroscope defini dans l'objet Inputs de UnderControl
      //et dans l'espace relatif de l'objet (Space.self)
      var pos=Vector2.zero;
      //var dif= "Vertical";
      //Debug.Log(Inputs.GetAxis("Vertical"+nr));
      if(Mathf.Abs(Inputs.GetAxis("Vertical"+nr)) < 0.2) return;
      transform.Translate(Vector3.forward * -Inputs.GetAxis("Vertical"+nr)*Speed*(SpeedSliderValue/2), Space.Self);   
   }
}


Auteur:  yann.minh [ Dim Avr 28, 2013 8:56 pm ]
Sujet du message:  Re: Unity-3D-NooGyroCamera-

Gyro-Jump-YM

Ajustement du saut de la camera


Code:
#pragma strict
#pragma implicit
#pragma downcast

public var Speed : float= 0.5;


var rotation=Vector3.zero;
var moveable=true;
var nr="";


   function Update () {
   if (Inputs.GetButton ("Jump"))
   
    {   
   
   transform.Translate(Vector3.up *Speed, Space.Self);
   
      //------Deplace l'objet en avant et arriere en fonction de l'axe "Vertical" du gyroscope defini dans l'objet Inputs de UnderControl
      //et dans l'espace relatif de l'objet (Space.self)


   


}
else
{

   transform.Translate(Vector3.up *0, Space.Self);
   
}

}

Auteur:  yann.minh [ Dim Avr 28, 2013 8:57 pm ]
Sujet du message:  Re: Unity-3D-NooGyroCamera-

Ajustement du déplacement latéral de la caméra



Code:
#pragma strict
#pragma implicit
#pragma downcast

public var Speed : float= 0.5;


var rotation=Vector3.zero;
var moveable=true;
var nr="";


   function Update () {
   if (Inputs.GetButton ("Jump"))
   
    {   
   
   transform.Translate(Vector3.up *Speed, Space.Self);
   
      //------Deplace l'objet en avant et arriere en fonction de l'axe "Vertical" du gyroscope defini dans l'objet Inputs de UnderControl
      //et dans l'espace relatif de l'objet (Space.self)


   


}
else
{

   transform.Translate(Vector3.up *0, Space.Self);
   
}

}

Auteur:  yann.minh [ Dim Avr 28, 2013 8:58 pm ]
Sujet du message:  Re: Unity-3D-NooGyroCamera-

La camera repousse les objets qu'elle rencontre


Character-PushAnyObject


Code:
//ENG: this script pushes all rigidbodies that the character touches
//ESP: este script empuja todos los rigidbodies que el personaje toca
var pushPower = 2.0;
function OnControllerColliderHit (hit : ControllerColliderHit)
{
var body : Rigidbody = hit.collider.attachedRigidbody;
//ENG: no rigidbody
//ESP: no hay rigidbody
if (body == null || body.isKinematic)
return;

//ENG: We dont want to push objects below us
//ESP: no queremos empujar objetos que esten detras nuestro
if (hit.moveDirection.y < -0.3)
return;

//ENG: Calculate push direction from move direction,  we only push objects to the sides never up and down
//ESP: calcular la direccion del empujon desde la direccion de movimiento
var pushDir = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);

//ENG: If you know how fast your character is trying to move, then you can also multiply the push velocity by that.
//ESP: si quieres saber como de rapido esta intentando tu personaje moverse, entonces puedes tambien multiplicar la velocidad de empujón por ello

//ENG: Apply the push
//ESP: Aplica el empujón
body.velocity = pushDir * pushPower;
}

Auteur:  yann.minh [ Dim Avr 28, 2013 9:00 pm ]
Sujet du message:  Re: Unity-3D-NooGyroCamera-

Effets de particules déclenchés par déplacement

EmitPropulsor-NooGyroCam-UC1


Code:
//ENG: This scripts emit particles and flick a light when you push certain button. attach it to an controlable game object with a light and particle emmiter game component
//ESP: este script hace emitir particulas y hacer parpadear una luz cuando pulsas cierto boton, adjuntalo a un objeto controlable con componente de emisor de particulas y componente de luz
var jetsound:AudioClip; //ENG:The sound clip
                        //ESP: el clip de sonido
var soundrate : float = 0.02;//ENG: sound playing ratio
                              //ESP: ratio de emitir sonido
private var nextsound = 0.0;   //ENG: time left to play next sound
                                 //ESP: timpo que queda para reproducir el siguiente sonido
var duration = 1.0;   //ENG: light flickering duration
                     //ESP: duración de la luz parpadeante
function Update () {
//ENG: if you push up, emit particle and start to flick the light intensity, else, stop emmiting particles and put light intensity to 0
//ESP: si pulsas arriba, emite particulas y empieza a parpadear la intensidad de la luz, si no, para de emitir particulas y pone la intensidad de la luz a 0
if(Inputs.GetAxis("Vertical") < 0)
{
   particleEmitter.emit = true;


var phi = Time.time / duration * 2 * Mathf.PI;

var amplitude = Mathf.Cos( phi ) * 0.5 + 0.5;

light.intensity = amplitude*3;

   if(Time.time > nextsound)
   {
      //ENG: play audio clip
      //ESP: reproducir el clip de audio
      if(jetsound)
         audio.PlayOneShot(jetsound);
      nextsound = Time.time + soundrate;
   }
}
else
{
   particleEmitter.emit = false;
   light.intensity = 0;
   
}

}

Auteur:  yann.minh [ Dim Avr 28, 2013 9:01 pm ]
Sujet du message:  Re: Unity-3D-NooGyroCamera-

Feu de position babord


Code:
//ENG: This scripts emit particles and flick a light when you push certain button. attach it to an controlable game object with a light and particle emmiter game component
//ESP: este script hace emitir particulas y hacer parpadear una luz cuando pulsas cierto boton, adjuntalo a un objeto controlable con componente de emisor de particulas y componente de luz
//var jetsound:AudioClip; //ENG:The sound clip
                        //ESP: el clip de sonido
//var soundrate : float = 0.02;//ENG: sound playing ratio
                              //ESP: ratio de emitir sonido
//private var nextsound = 0.0;   //ENG: time left to play next sound
                                 //ESP: timpo que queda para reproducir el siguiente sonido
var duration = 1.0;   //ENG: light flickering duration
                     //ESP: duración de la luz parpadeante




function Update () {
//ENG: if you push up, emit particle and start to flick the light intensity, else, stop emmiting particles and put light intensity to 0
//ESP: si pulsas arriba, emite particulas y empieza a parpadear la intensidad de la luz, si no, para de emitir particulas y pone la intensidad de la luz a 0
if(Input.GetAxis("Horizontal") < 0)
{
//   particleEmitter.emit = true;
var phi = Time.time / duration * 2 * Mathf.PI;
var amplitude = Mathf.Cos( phi ) * 0.5 + 0.5;
light.intensity = amplitude*3;
}


else
{

   light.intensity = 0;

}

}

/*   if(Time.time > nextsound)
   {
      //ENG: play audio clip
      //ESP: reproducir el clip de audio
      if(jetsound)
         audio.PlayOneShot(jetsound);
      nextsound = Time.time + soundrate;
   }
}

else
{
   particleEmitter.emit = false;
   light.intensity = 0;

}

}
*/

Auteur:  yann.minh [ Dim Avr 28, 2013 9:02 pm ]
Sujet du message:  Re: Unity-3D-NooGyroCamera-

Feu de position tribord


Code:
//ENG: This scripts emit particles and flick a light when you push certain button. attach it to an controlable game object with a light and particle emmiter game component
//ESP: este script hace emitir particulas y hacer parpadear una luz cuando pulsas cierto boton, adjuntalo a un objeto controlable con componente de emisor de particulas y componente de luz
//var jetsound:AudioClip; //ENG:The sound clip
                        //ESP: el clip de sonido
//var soundrate : float = 0.02;//ENG: sound playing ratio
                              //ESP: ratio de emitir sonido
//private var nextsound = 0.0;   //ENG: time left to play next sound
                                 //ESP: timpo que queda para reproducir el siguiente sonido
var duration = 1.0;   //ENG: light flickering duration
                     //ESP: duración de la luz parpadeante




function Update () {
//ENG: if you push up, emit particle and start to flick the light intensity, else, stop emmiting particles and put light intensity to 0
//ESP: si pulsas arriba, emite particulas y empieza a parpadear la intensidad de la luz, si no, para de emitir particulas y pone la intensidad de la luz a 0
if(Input.GetAxis("Horizontal") > 0)
{
//   particleEmitter.emit = true;
var phi = Time.time / duration * 2 * Mathf.PI;
var amplitude = Mathf.Cos( phi ) * 0.5 + 0.5;
light.intensity = amplitude*3;
}


else
{

   light.intensity = 0;

}

}

/*   if(Time.time > nextsound)
   {
      //ENG: play audio clip
      //ESP: reproducir el clip de audio
      if(jetsound)
         audio.PlayOneShot(jetsound);
      nextsound = Time.time + soundrate;
   }
}

else
{
   particleEmitter.emit = false;
   light.intensity = 0;

}

}
*/

Auteur:  yann.minh [ Dim Avr 28, 2013 9:04 pm ]
Sujet du message:  Re: Unity-3D-NooGyroCamera-

Camera embarquée

Gyro-Move-Camera-YM-2(Block)

Code:
#pragma strict
#pragma implicit
#pragma downcast
var rotation=Vector3.zero;
var moveable=true;
var nr="";
function Update () {
   if(moveable){
      //rigidbody.velocity=Vector3(Inputs.GetAxis("Horizontal"+nr)*5,rigidbody.velocity.y,Inputs.GetAxis("Vertical"+nr)*5);
            
            
      //rigidbody.velocity=Vector3((Inputs.GetAxis("Horizontal"+nr)*5,rigidbody.velocity.y,Inputs.GetAxis("Vertical")*5);
      
      //------Deplace l'objet en avant et arriere en fonction de l'axe "Vertical" du gyroscope defini dans l'objet Inputs de UnderControl
      //et dans l'espace relatif de l'objet (Space.self)
      //var pos=Vector2.zero;
      //transform.Translate(Vector3.forward * Inputs.GetAxis("Vertical"+nr)/8, Space.Self);
      
      
      //------ Impose d'appuyer sur un des boutons de IPod definis dans l'objet Inputs de Undercontrol.
      //if(Inputs.GetButton("Hold"))
      
   
      //------ Defini l'orientation x en fonction de la position "horizontal" de l'Ipod, et l'orientation y en fonction de la position "vertical" de l'Ipod   
         //pos=Vector2(Inputs.GetAxis("Horizontal"+nr),Inputs.GetAxis("Vertical"+nr));
      pos=Vector2(Inputs.GetAxis("Horizontal"+nr),Inputs.GetAxis("Vertical"+nr));
         
      //------ Effectue une rotation horizontale en fonction de l'orientation "Horizontal" de l'Ipod definie dans l'objet Inputs de UnderControl   
       //rotation.y=-pos.x*500;
       rotation.y=Mathf.Lerp(180+rotation.y,180-pos.x*-100,Time.deltaTime)-180;
   
      
      //------ Effectue un basculement frontal en fonction de l'orientation "Vertical" de l'Ipod definie dans l'objet Inputs de UnderControl   
      //rotation.x=pos.y*30;
      rotation.x=Mathf.Lerp(180+rotation.x,180-pos.y*50,Time.deltaTime)-180;
      
      transform.localEulerAngles=rotation;
      
      
      
   }
}

/*function OnTriggerEnter(info: Collider){
   movable=false;
   Camera.main.SendMessage("Next",info.gameObject);
   Camera.main.SendMessage("DestroyMe",gameObject);

}

*/

Auteur:  yann.minh [ Dim Avr 28, 2013 9:05 pm ]
Sujet du message:  Re: Unity-3D-NooGyroCamera-

GUN BOOK


lanceur de projectiles

Code:
var shotsound:AudioClip;
var shellPrefab : GameObject;
var proyectilevelocity:int;
var ammo:int;
var fireRate = 1.0;
private var nextfire = 0.0;
function FixedUpdate () {
   if (Inputs.GetButton ("Fire") && Time.time>nextfire && ammo>0)
      ShotProyectile();
}
function ShotProyectile(){
      if(Time.time > nextfire)
      {
   var Grenade:GameObject = Instantiate(shellPrefab,transform.position,transform.rotation);
   Grenade.GetComponentInChildren(Rigidbody).velocity =transform.TransformDirection(Vector3(0,0,proyectilevelocity));
   //Physics.IgnoreCollision(shellPrefab.GetComponentInChildren(BoxCollider).collider,transform.parent.collider);
   ammo--;
   if(shotsound)
      audio.PlayOneShot(shotsound);
   Destroy(Grenade,10);
   nextfire = Time.time+fireRate;}
}

Auteur:  yann.minh [ Dim Avr 28, 2013 9:07 pm ]
Sujet du message:  Re: Unity-3D-NooGyroCamera-

A mettre dans le projectile


ContinuousCollision-Instance

Code:
//ENG: this scripts let you instantiate continuosly objects (sparks per example). you must attach this script to an object with rigidbody
//ESP: este script te permite instanciar continuamente objetos (chispas, por ejemplo). debes adjuntar este script a un objeto con rigidbody
var Sparks:GameObject;    //ENG: the object that you wanna instance
                           //ESP: el objeto que quieres instanciar
var timerate = 0.1;   //ENG: time rate that is instanced the object
                     //ESP: ratio de tiempo en el que el objeto es instanciado
private var nextinstance=0.0;
function OnCollisionStay(collision : Collision)
{

   var contact = collision.contacts[0];
   var rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
   var pos = contact.point;
   //ENG:When the magnitude is higher  and the rate is over, instance again
   //ESP: cuando la magnitud del impacto es alta y el ratio se acaba, instancia otra vez
   if(collision.relativeVelocity.magnitude > 0.1 && Time.time>nextinstance)
   {
      nextinstance = Time.time + timerate;
      Instantiate(Sparks, pos, rot);
   }
}

Auteur:  yann.minh [ Dim Avr 28, 2013 9:08 pm ]
Sujet du message:  Re: Unity-3D-NooGyroCamera-

A mettre dans l'objet particle system du projectile


Code:
//ENG: This scripts emit particles and flick a light when you push certain button. attach it to an controlable game object with a light and particle emmiter game component
//ESP: este script hace emitir particulas y hacer parpadear una luz cuando pulsas cierto boton, adjuntalo a un objeto controlable con componente de emisor de particulas y componente de luz
var jetsound:AudioClip; //ENG:The sound clip
                        //ESP: el clip de sonido
var soundrate : float = 0.02;//ENG: sound playing ratio
                              //ESP: ratio de emitir sonido
private var nextsound = 0.0;   //ENG: time left to play next sound
                                 //ESP: timpo que queda para reproducir el siguiente sonido
var duration = 1.0;   //ENG: light flickering duration
                     //ESP: duración de la luz parpadeante
function Update () {
//ENG: if you push up, emit particle and start to flick the light intensity, else, stop emmiting particles and put light intensity to 0
//ESP: si pulsas arriba, emite particulas y empieza a parpadear la intensidad de la luz, si no, para de emitir particulas y pone la intensidad de la luz a 0
if(Input.GetAxis("Vertical") > 0)
{
   particleEmitter.emit = true;


var phi = Time.time / duration * 2 * Mathf.PI;

var amplitude = Mathf.Cos( phi ) * 0.5 + 0.5;

light.intensity = amplitude*3;

   if(Time.time > nextsound)
   {
      //ENG: play audio clip
      //ESP: reproducir el clip de audio
      if(jetsound)
         audio.PlayOneShot(jetsound);
      nextsound = Time.time + soundrate;
   }
}
else
{
   particleEmitter.emit = false;
   light.intensity = 0;
   
}

}

Page 1 sur 1 Heures au format UTC [ Heure d’été ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/