Search Unity

ETeeskiTutorials mouse look problem

Discussion in 'Scripting' started by Zwero, Jun 26, 2012.

  1. Zwero

    Zwero

    Joined:
    Jun 26, 2012
    Posts:
    7
    FPS1.2 Mouse look script

    SOLVED ... I writed wrong Input and didn't used * ... Thanx again but now i have another problem

    FPS1.4 Setting Max speed ....

    SOLVED again :)) thank ETeeski luv your tutorial

    ok so .... FPS 1.7 Limited air control

    Yep i walk smooth and nice but when i press the jump button and i'm in mid air my speed goes crazy ...like var maxWalkspeed 100000 ... please help and FPS 1.8 When i press play my gun "spawns" too much forward and upward then i seted ... please help ... oh yeah ... and if i try to set variables like you:
    when i touch the floor my "character" is flying away with 2000KM/H xD help pleaseeee
    SPEED script

    var walkAcceleration : float = 1000;
    @HideInInspector
    var walkDeaccelerationVolx : float;
    var walkAccelAirRacio : float = 0.1;
    var walkDeacceleration : float = 0.1;
    var cameraObject : GameObject;
    var maxWalkSpeed : float = 20;
    @HideInInspector
    var horizontalMovement : Vector3;

    var jumpVelocity : float = 300;
    @HideInInspector
    var grounded : boolean = false;
    var maxSlope : float = 60;

    function Update ()
    {
    horizontalMovement = Vector3(rigidbody.velocity.x, rigidbody.velocity.z);
    if (horizontalMovement.magnitude > maxWalkSpeed)
    {
    horizontalMovement = horizontalMovement.normalized;
    horizontalMovement *= maxWalkSpeed;
    }

    rigidbody.velocity.x = Mathf.SmoothDamp(rigidbody.velocity.x,0 ,walkDeaccelerationVolx, walkDeacceleration);
    rigidbody.velocity.z = Mathf.SmoothDamp(rigidbody.velocity.z,0 ,walkDeaccelerationVolx, walkDeacceleration);

    if (grounded)
    {
    rigidbody.velocity.x /= walkDeacceleration;
    rigidbody.velocity.z /= walkDeacceleration;
    }
    transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(MouseLookScript).currentYRotation, 0);
    if (grounded)
    rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration * Time.deltaTime, 0, Input.GetAxis("Vertical") * walkAcceleration * Time.deltaTime);
    else
    rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration * Time.deltaTime, 0, Input.GetAxis("Vertical") * walkAcceleration * Time.deltaTime);

    if(Input.GetButtonDown("Jump") grounded)
    rigidbody.AddForce(0,jumpVelocity,0);
    }

    function OnCollisionStay (collision : Collision)
    {
    for (var contact : ContactPoint in collision.contacts)
    {
    if (Vector3.Angle(contact.normal, Vector3.up) <maxSlope)
    grounded = true;
    }
    }

    function OnCollisionExit ()
    {
    grounded = false;
    }



    AND GUN


    var cameraObject : GameObject;
    @HideInInspector
    var targetXRotation : float;
    @HideInInspector
    var targetYRotation : float;
    @HideInInspector
    var targetXRotationV : float;
    @HideInInspector
    var targetYRotationV : float;

    var rotationSpeed : float = 0.3;

    var holdHeight : float = -0.5;
    var holdSide : float = 0.5;
    function Update ()
    {
    transform.position = cameraObject.transform.position + (Quaternion.Euler(0,targetYRotation,0) * Vector3(holdSide, holdHeight,0));
    }



    FPS1.9 Aiming ... When i press right click my gun goes too much in left ... isn't in middle of screen ... how can i solve this?


    SCRIPT

    var cameraObject : GameObject;
    @HideInInspector
    var targetXRotation : float;
    @HideInInspector
    var targetYRotation : float;
    @HideInInspector
    var targetXRotationV : float;
    @HideInInspector
    var targetYRotationV : float;

    var rotationSpeed : float = 0.1;

    var holdHeight : float = -0.3;
    var holdSide : float = 0.5;
    var racioHipHold : float = 1;
    var hipToAimSpeed : float =0.1;
    @HideInInspector
    var racioHipHoldV : float;
    function Update ()
    {

    if (Input.GetButton("Fire2"))
    racioHipHold = Mathf.SmoothDamp(racioHipHold, 0, racioHipHoldV, hipToAimSpeed);

    if (Input.GetButton("Fire2") == false)
    racioHipHold = Mathf.SmoothDamp(racioHipHold, 1, racioHipHoldV, hipToAimSpeed);

    transform.position = cameraObject.transform.position + (Quaternion.Euler(0,targetYRotation,0) * Vector3(holdSide * racioHipHold, holdHeight * racioHipHold,0));
    targetXRotation = Mathf.SmoothDamp( targetXRotation, cameraObject.GetComponent(MouseLookScript).xRotation, targetXRotationV, rotationSpeed);
    targetYRotation = Mathf.SmoothDamp( targetYRotation, cameraObject.GetComponent(MouseLookScript).yRotation, targetYRotationV, rotationSpeed);

    transform.rotation = Quaternion.Euler(targetXRotation, targetYRotation, 0);
    }
     
    Last edited: Jun 27, 2012
  2. eteeski

    eteeski

    Joined:
    Feb 2, 2010
    Posts:
    476
    lol thanks :)
     
  3. prietokevin

    prietokevin

    Joined:
    Dec 19, 2016
    Posts:
    3
    that is a new code; maybe Someone can help me on that part
    Code (JavaScript):
    1.  
    2. rb=GetComponent.<Rigidbody>();
    3.  
    4. horizontalMovement = Vector2(rb.velocity.x,rb.velocity.z);
    5.         if (horizontalmovement.magnitude > maxWalkSpeed)
    6.         {
    7.             horizontalmovement = horizontalmovement.normalized;
    8.              horizontalmovement *= maxWalkSpeed;
    9.         }