Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

First Person Controller

Discussion in 'iOS and tvOS' started by scinfu, Oct 28, 2008.

  1. scinfu

    scinfu

    Joined:
    Oct 23, 2008
    Posts:
    404
    where can i found First Person Controller ?

    and in my unity iphone why i dont have 'Standard Assets'' or ''Pro Standard Assets'' ?
     
  2. drag0nsphere

    drag0nsphere

    Joined:
    Nov 7, 2007
    Posts:
    285
    Look in /Applications/Unity/Standard Packages/Standard Assets.unitypackage
    or where you saved it.

    It wont have any iphone control support yet, but that should not be too hard to implement.
     
  3. scinfu

    scinfu

    Joined:
    Oct 23, 2008
    Posts:
    404
    /Applications/Unity/Standard Packages/Standard Assets.unitypackage


    this is not for iphone ... it s for unity indie ...or function in iphone ?
     
  4. drag0nsphere

    drag0nsphere

    Joined:
    Nov 7, 2007
    Posts:
    285
    Im starting to go through and convert the FPS scripts for the iphone....
    here is mouse look...
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. [AddComponentMenu("iPhone/Camera-Control/Mouse Look")]
    6. public class MouseLook : MonoBehaviour {
    7.  
    8.     public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
    9.     public RotationAxes axes = RotationAxes.MouseXAndY;
    10.     public float sensitivityX = 15F;
    11.     public float sensitivityY = 15F;
    12.  
    13.     public float minimumX = -360F;
    14.     public float maximumX = 360F;
    15.  
    16.     public float minimumY = -60F;
    17.     public float maximumY = 60F;
    18.  
    19.     float rotationX = 0F;
    20.     float rotationY = 0F;
    21.    
    22.     Quaternion originalRotation;
    23.  
    24.     void Update ()
    25.     {
    26.         if (axes == RotationAxes.MouseXAndY)
    27.         {
    28.             // Read the mouse input axis
    29.             rotationX += iPhoneInput.acceleration.x * sensitivityX;
    30.             rotationY += iPhoneInput.acceleration.y * sensitivityY;
    31.  
    32.             rotationX = ClampAngle (rotationX, minimumX, maximumX);
    33.             rotationY = ClampAngle (rotationY, minimumY, maximumY);
    34.            
    35.             Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
    36.             Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
    37.            
    38.             transform.localRotation = originalRotation * xQuaternion * yQuaternion;
    39.         }
    40.         else if (axes == RotationAxes.MouseX)
    41.         {
    42.             rotationX += iPhoneInput.acceleration.x * sensitivityX;
    43.             rotationX = ClampAngle (rotationX, minimumX, maximumX);
    44.  
    45.             Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
    46.             transform.localRotation = originalRotation * xQuaternion;
    47.         }
    48.         else
    49.         {
    50.             rotationY += iPhoneInput.acceleration.y * sensitivityY;
    51.             rotationY = ClampAngle (rotationY, minimumY, maximumY);
    52.  
    53.             Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
    54.             transform.localRotation = originalRotation * yQuaternion;
    55.         }
    56.     }
    57.    
    58.     void Start ()
    59.     {
    60.         // Make the rigid body not change rotation
    61.         if (rigidbody)
    62.             rigidbody.freezeRotation = true;
    63.         originalRotation = transform.localRotation;
    64.     }
    65.    
    66.     public static float ClampAngle (float angle, float min, float max)
    67.     {
    68.         if (angle < -360F)
    69.             angle += 360F;
    70.         if (angle > 360F)
    71.             angle -= 360F;
    72.         return Mathf.Clamp (angle, min, max);
    73.     }
    74. }
    75.  
    Its a c# script
     
  5. scinfu

    scinfu

    Joined:
    Oct 23, 2008
    Posts:
    404
    ok now i see


    :wink: :wink: :wink: :wink:
    tks
     
  6. drag0nsphere

    drag0nsphere

    Joined:
    Nov 7, 2007
    Posts:
    285
    and here is the FPS walker

    Code (csharp):
    1.  
    2. var speed = 6.0;
    3. var jumpSpeed = 8.0;
    4. var gravity = 20.0;
    5.  
    6.  
    7. private var moveDirection = Vector3.zero;
    8. private var grounded : boolean = false;
    9.  
    10. function FixedUpdate() {
    11.     if (grounded) {
    12.         // We are grounded, so recalculate movedirection directly from axes
    13.         moveDirection = new Vector3 (iPhoneInput.acceleration.y, 0,iPhoneInput.acceleration.x);
    14.         moveDirection = transform.TransformDirection(moveDirection);
    15.         moveDirection *= speed;
    16.        
    17.         if (Input.GetButton ("Jump")) {
    18.             moveDirection.y = jumpSpeed;
    19.         }
    20.     }
    21.  
    22.     // Apply gravity
    23.     moveDirection.y -= gravity * Time.deltaTime;
    24.    
    25.     // Move the controller
    26.     var controller : CharacterController = GetComponent(CharacterController);
    27.     var flags = controller.Move(moveDirection * Time.deltaTime);
    28.     grounded = (flags  CollisionFlags.CollidedBelow) != 0;
    29. }
    30.  
    31. @script RequireComponent(CharacterController)
    32.  
    you may want to tweak it as having both scripts mapped to the accelerometer will mess it up.
     
  7. scinfu

    scinfu

    Joined:
    Oct 23, 2008
    Posts:
    404
    you're a big ... I'm trying to put them into practice these codes.

    thanks thanks thanks thanks
     
  8. drag0nsphere

    drag0nsphere

    Joined:
    Nov 7, 2007
    Posts:
    285
    It was really simple.. all i did was replace the previous input with
    Code (csharp):
    1.  
    2. iPhoneInput.acceleration.x or y
    3.  
    No problem.. glad to help :)
     
  9. scinfu

    scinfu

    Joined:
    Oct 23, 2008
    Posts:
    404
    interesting!

    but this script only be replaced at the original?
     
  10. scinfu

    scinfu

    Joined:
    Oct 23, 2008
    Posts:
    404
    the scripts dont function...


    i replace the originl with your but dont functions


    any idea ?
     
  11. psychicparrot

    psychicparrot

    Joined:
    Dec 10, 2007
    Posts:
    884
    What's happening? There is no way anyone can solve your problem with just 'dont functions'. Try being more specific, like saying what error you are getting or what is happening.
     
  12. scinfu

    scinfu

    Joined:
    Oct 23, 2008
    Posts:
    404
    ok sorry

    in this code the first person move left and right ... i wont to rotate it .


    Code (csharp):
    1.  
    2. var speed = 6.0;
    3. var jumpSpeed = 8.0;
    4. var gravity = 20.0;
    5.  
    6.  
    7. private var moveDirection = Vector3.zero;
    8. private var grounded : boolean = false;
    9.  
    10. function FixedUpdate() {
    11.    if (grounded) {
    12.       // We are grounded, so recalculate movedirection directly from axes
    13.       moveDirection = new Vector3 (iPhoneInput.acceleration.y, 0,iPhoneInput.acceleration.x);
    14.       moveDirection = transform.TransformDirection(moveDirection);
    15.       moveDirection *= speed;
    16.        
    17.       if (Input.GetButton ("Jump")) {
    18.          moveDirection.y = jumpSpeed;
    19.       }
    20.    }
    21.  
    22.    // Apply gravity
    23.    moveDirection.y -= gravity * Time.deltaTime;
    24.    
    25.    // Move the controller
    26.    var controller : CharacterController = GetComponent(CharacterController);
    27.    var flags = controller.Move(moveDirection * Time.deltaTime);
    28.    grounded = (flags  CollisionFlags.CollidedBelow) != 0;
    29. }
    30.  
    31. @script RequireComponent(CharacterController)
    32.  
    33.  
     
  13. Aaron

    Aaron

    Joined:
    Oct 22, 2008
    Posts:
    122
    Scinfu are you making sure to attach the scripts to the camera, and player objects?
     
  14. scinfu

    scinfu

    Joined:
    Oct 23, 2008
    Posts:
    404
    ok now function all ...


    thanks thanks thanks



    :wink: :wink: :wink: :wink: :wink: :wink: :wink: :wink: :wink: :wink: :wink: :wink: :wink: :wink: :wink: :wink: :wink: :wink: :wink: :wink: :wink: :wink: :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D