ETeeskiTutorials FPS1 Problem Diagnostic Collaboration Thread

Discussion in 'Teaching' started by eteeski, Mar 5, 2012.

  1. eteeski

    eteeski

    Member

    Joined:
    Feb 2, 2010
    Messages:
    465
    youtube.com/ETeeskiTutorials
    Click Here to go to the FPS1 Tutorial Playlist

    This video explains the idea of this thread:

    Screw what I said in the video, just post your glitches and questions in this thread.

    Be sure so scroll through other people's posts here; Someone else might have had the same problem as you, or you may find someone who is having a problem that you figured out last week.
    I will still personally try to respond and help everyone with whatever problems they are having, and I think I will be able to do this more effectively on the forums.


    Here's a link to a video by ReaperZ1997 on how to fix the gun rotation and position:
    http://www.youtube.com/watch?v=TGyTGD7yRo0
    Last edited: Oct 3, 2013
  2. rmail2006

    rmail2006

    New Member

    Joined:
    Jul 22, 2010
    Messages:
    73
    Hi,
    Great tutorials :D

    FPS1.19

    When walking with the headbob script my gun is going crazy shaking all over the place.

    I've changed Update to LateUpdate but it's still shaking when I walk
  3. DrSega

    DrSega

    New Member

    Joined:
    Mar 6, 2012
    Messages:
    157
  4. GeekFreek

    GeekFreek

    New Member

    Joined:
    Mar 7, 2012
    Messages:
    1
    How about a tutorial on how to create a first-person camera conversion to third person camera. Using the scroll wheel to move between them or automated for "cut" sequences?
  5. benjwano

    benjwano

    New Member

    Joined:
    Mar 5, 2012
    Messages:
    6
  6. vipvex

    vipvex

    Member

    Joined:
    Dec 6, 2011
    Messages:
    58
  7. equalspotato

    equalspotato

    New Member

    Joined:
    Mar 11, 2012
    Messages:
    3
  8. TKFiyah

    TKFiyah

    New Member

    Joined:
    Mar 15, 2012
    Messages:
    7
  9. Squall Leonhart

    Squall Leonhart

    New Member

    Joined:
    Mar 17, 2012
    Messages:
    4
  10. Squall Leonhart

    Squall Leonhart

    New Member

    Joined:
    Mar 17, 2012
    Messages:
    4
  11. CameronCBTV

    CameronCBTV

    New Member

    Joined:
    Mar 20, 2012
    Messages:
    1
  12. hijsm

    hijsm

    New Member

    Joined:
    Mar 22, 2012
    Messages:
    1
  13. lordhoban

    lordhoban

    New Member

    Joined:
    Mar 24, 2012
    Messages:
    6
    What video covers the UseKey script, which supposedly is in the video dealing with picking up guns?. A video I haven't been able to find. Quick help would be much appreciated, as I'm kind of on a deadline here and this one little thing is hanging me up.
  14. YourSeedyUncle

    YourSeedyUncle

    New Member

    Joined:
    Mar 27, 2012
    Messages:
    8
    My gun has sort of a jittering motion? If that makes sense. The gun jumps left and right slightly when I rotate the screen and it does it more profusely when I move forward and rotate. And I skipped 1.23 and went to 1.24 because I wanted to do some stuff but didn't have enough time for a long vid, so I did 1.24 and then did 1.23

    EDIT: Also I didn't add the script because I don't think it has to do with my script. I will if you tell me to. And changing the layer from guns doesn't change anything

    Link: http://forum.unity3d.com/threads/12...screen-(EteeskiTutorials)?p=874783#post874783
    Last edited: Mar 27, 2012
  15. ViFFeX

    ViFFeX

    New Member

    Joined:
    Mar 28, 2012
    Messages:
    4
    Hi ETeeski,

    I have a generic question, of something I noticed while using my imported gun model.

    For some reason, when I am zoomed out the Raycast is not centered on screen. At least, that's what I think as the bulletHole object gets created off center to the right.

    When aiming it's all perfect. It lines up perfectly with the gun. Just as soon as I am zoomed out the bullets are offset to the side.

    Is this something I can fix in code? Or something that I have to fix in the Inspector?

    I have my gun's local coordinates at x: 0, y: 0, and z: 0.75.

    My thread can be found here http://forum.unity3d.com/threads/129888-Raycast-doesn-t-get-centered?p=876420#post876420, where you can also find a link to a early iteration of my FPS which seems to be having the same issue.
  16. kermitt

    kermitt

    Member

    Joined:
    Feb 14, 2012
    Messages:
    7
    Hi ETeeski,
    first thank you very much for these instructive tutorilas. In FPS1.11, I'd like to understand why we use - as in other parts of the code - both smoothDamp and Lerp to get a smooth transition. ┬┐Wouldn't be enough to smoothDamp between both camera FOVs?
    My thread: http://forum.unity3d.com/threads/129959-FPS1.11-ETeeski-Tutorials
  17. ViFFeX

    ViFFeX

    New Member

    Joined:
    Mar 28, 2012
    Messages:
    4
    Another generic Gameplay question: When pressing both A+S or A+W or D+S or D+W (ergo: Horizontal Vertical movement at the same time) the character walks diagonally at twice the speed it is allowed to move, even though the maxWalkSpeed is set.

    Is there a way to always limit the movement speed to maxWalkSpeed? Even if multiple keys are pressed?
  18. dreadt9

    dreadt9

    Member

    Joined:
    Jan 13, 2012
    Messages:
    140
    Hey,
    For my character he is using a capsule collider and rigid body for a movement motor.
    i know you have a tutorial for stairs but that doesn't apply for the capsule collider and rigid body.
    Is there any way to edit the following script to create like a step offset?

    Code (csharp):
    1. var crouchSpeed = 2.0;
    2. var walkSpeed = 8.0;
    3. var runSpeed = 20.0;
    4.  
    5. var fallDamageMultiplier : int = 2;
    6. var fallAnimGO : GameObject;
    7. var inAirControl = 0.1;
    8. var gravity = 20.0;
    9. var maxVelocityChange = 10.0;
    10. var canJump = true;
    11. var jumpHeight = 2.0;
    12. var fallSound : AudioClip;
    13. var playerWeapons : GameObject;
    14.  
    15. var grounded = false;
    16. private var sliding : boolean = false;
    17. private var speed = 10.0;
    18. private var limitDiagonalSpeed = true;
    19. private var crouching : boolean;
    20. private var normalHeight : float = 0.5;
    21. private var crouchHeight : float = -0.2;
    22. private var crouchingHeight = 0.3;
    23. private var hit : RaycastHit;
    24. private var myTransform : Transform;
    25. private var rayDistance : float;
    26. private var mainCameraGO : GameObject;
    27. private var weaponCameraGO : GameObject;
    28.  
    29. @script RequireComponent(Rigidbody, CapsuleCollider)
    30.  
    31. function Awake (){
    32.     rigidbody.freezeRotation = true;
    33.     rigidbody.useGravity = false;
    34.     myTransform = transform;
    35.     mainCameraGO = gameObject.FindWithTag("MainCamera");
    36.     weaponCameraGO = gameObject.FindWithTag("WeaponCamera");
    37.     rayDistance = collider.height * .5 + collider.radius;
    38.     playerWeapons.animation.wrapMode = WrapMode.Loop;
    39. }
    40.  
    41. function FixedUpdate (){
    42.     if (grounded){         
    43.         var inputX = Input.GetAxis("Horizontal");
    44.         var inputY = Input.GetAxis("Vertical");
    45.         var inputModifyFactor = (inputX != 0.0  inputY != 0.0  limitDiagonalSpeed)? .7071 : 1.0;
    46.        
    47.         if (Physics.Raycast(myTransform.position, -Vector3.up, hit, rayDistance)) {
    48.             if (Vector3.Angle(hit.normal, Vector3.up) > 30){
    49.                 sliding = true;
    50.                 rigidbody.AddRelativeForce (-Vector3.up * 500);
    51.             }else{
    52.                 sliding = false;
    53.                
    54.             }  
    55.         }
    56.  
    57.         // Calculate how fast we should be moving
    58.         var targetVelocity = new Vector3(inputX * inputModifyFactor, 0.0, inputY * inputModifyFactor);
    59.         targetVelocity *= speed;   
    60.        
    61.         // Apply a force that attempts to reach our target velocity
    62.         var velocity = rigidbody.velocity;
    63.         var velocityChange = (targetVelocity - velocity);
    64.         velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
    65.         velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
    66.         velocityChange.y = 0;
    67.         rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);
    68.    
    69.        
    70.         if (canJump  Input.GetButton("Jump")){
    71.             rigidbody.velocity = Vector3(velocity.x, CalculateJumpVerticalSpeed(), velocity.z);
    72.         }
    73.        
    74.         if(!crouching){
    75.             if (grounded  Input.GetButton("Run")  Input.GetKey("w"))
    76.                 speed = runSpeed;
    77.                 else
    78.                 speed = walkSpeed;
    79.             }else{
    80.             speed = crouchSpeed;
    81.         }
    82.    
    83.     }else{
    84.    
    85.         // AirControl
    86.         targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
    87.         targetVelocity = transform.TransformDirection(targetVelocity) * inAirControl;
    88.         rigidbody.AddForce(targetVelocity, ForceMode.VelocityChange);
    89.     }
    90.  
    91.     // Gravity
    92.     rigidbody.AddForce(Vector3 (0, -gravity * rigidbody.mass, 0));
    93.     grounded = false;
    94. }
    95.  
    96. function OnCollisionStay (col : Collision){
    97.     if (Physics.Raycast(myTransform.position, -Vector3.up, hit, rayDistance)) {
    98.         grounded = true;
    99.     }  
    100. }
    101.  
    102. function HitJumpPad(velocity: float) {
    103.        rigidbody.velocity.z += velocity;
    104.     }
    105.  
    106. function OnCollisionEnter (collision : Collision){
    107.     if(!grounded){
    108.         fallAnimGO.animation.CrossFadeQueued("Fall", 0.3, QueueMode.PlayNow);
    109.         var currSpeed : float = collision.relativeVelocity.magnitude;
    110.        
    111.         if (currSpeed > 20) {
    112.             var damage : float = currSpeed * fallDamageMultiplier;
    113.             Debug.Log ("FallDamage" + damage);
    114.             SendMessage ("PlayerDamage", damage, SendMessageOptions.DontRequireReceiver);
    115.         }  
    116.     }  
    117. }
    118.  
    119. function CalculateJumpVerticalSpeed (){
    120.     return Mathf.Sqrt(2 * jumpHeight * gravity);
    121. }
    122.  
    123. function Update(){
    124.  
    125.     if (grounded  rigidbody.velocity.magnitude < (walkSpeed+2)  rigidbody.velocity.magnitude > (walkSpeed-2)  !Input.GetButton("Fire2")){
    126.         playerWeapons.animation.CrossFade("Walk");
    127.        
    128.     }else if (grounded  rigidbody.velocity.magnitude < (runSpeed+2)  rigidbody.velocity.magnitude > (runSpeed -2)){
    129.         playerWeapons.animation.CrossFade("Run");
    130.        
    131.     }else if (grounded  rigidbody.velocity.magnitude < (crouchSpeed+1)  rigidbody.velocity.magnitude > (crouchSpeed-1)  Input.GetButton("Fire2"))
    132.         playerWeapons.animation.CrossFade("CrouchAim");
    133.    
    134.     else
    135.         playerWeapons.animation.CrossFade("IdleAnim");
    136.        
    137.    
    138.     if(mainCameraGO.transform.localPosition.y > normalHeight){
    139.         mainCameraGO.transform.localPosition.y = normalHeight;
    140.     } else if(mainCameraGO.transform.localPosition.y < crouchHeight){
    141.         mainCameraGO.transform.localPosition.y = crouchHeight;
    142.     }
    143.    
    144.     if(weaponCameraGO.transform.localPosition.y > normalHeight){
    145.         weaponCameraGO.transform.localPosition.y = normalHeight;
    146.     } else if(weaponCameraGO.transform.localPosition.y < crouchHeight){
    147.         weaponCameraGO.transform.localPosition.y = crouchHeight;
    148.     }
    149.    
    150.     if (Input.GetButtonDown("Crouch")  !crouching) {
    151.         collider.height = 1.5;
    152.         collider.center = Vector3 (0, -0.25, 0);
    153.         crouching = true;
    154.     }
    155.  
    156.     if(Input.GetButtonUp("Crouch")  crouching){
    157.         collider.height = 2.0;
    158.         collider.center = Vector3 (0, 0, 0);
    159.         crouching = false;
    160.     }
    161.    
    162.     if(crouching){
    163.         if(mainCameraGO.transform.localPosition.y > crouchHeight){
    164.             if(mainCameraGO.transform.localPosition.y - (crouchingHeight * Time.deltaTime/.1) < crouchHeight){
    165.                 mainCameraGO.transform.localPosition.y = crouchHeight;
    166.             } else {
    167.                 mainCameraGO.transform.localPosition.y -= crouchingHeight * Time.deltaTime/.1;
    168.             }
    169.         }
    170.         if(weaponCameraGO.transform.localPosition.y > crouchHeight){
    171.             if(weaponCameraGO.transform.localPosition.y - (crouchingHeight * Time.deltaTime/.1) < crouchHeight){
    172.                 weaponCameraGO.transform.localPosition.y = crouchHeight;
    173.             } else {
    174.                 weaponCameraGO.transform.localPosition.y -= crouchingHeight * Time.deltaTime/.1;
    175.             }
    176.         }
    177.  
    178.     } else {
    179.         if(mainCameraGO.transform.localPosition.y < normalHeight){
    180.             if(mainCameraGO.transform.localPosition.y + (crouchingHeight * Time.deltaTime/.1) > normalHeight){
    181.                 mainCameraGO.transform.localPosition.y = normalHeight;
    182.             } else {
    183.                 mainCameraGO.transform.localPosition.y += crouchingHeight * Time.deltaTime/.1;
    184.             }
    185.         }
    186.         if(weaponCameraGO.transform.localPosition.y < normalHeight){
    187.             if(weaponCameraGO.transform.localPosition.y + (crouchingHeight * Time.deltaTime/.1) > normalHeight){
    188.                 weaponCameraGO.transform.localPosition.y = normalHeight;
    189.             } else {
    190.                 weaponCameraGO.transform.localPosition.y += crouchingHeight * Time.deltaTime/.1;
    191.             }
    192.         }
    193.     }
    194. }
    195.  
    196. function Accelerate (accelerateY : float, accelerateZ : float){
    197.     grounded = false;
    198.     rigidbody.AddRelativeForce (0, accelerateY, accelerateZ);  
    199. }
  19. Deki3d

    Deki3d

    New Member

    Joined:
    Feb 20, 2012
    Messages:
    2
    I have problem when i set gunCamera depth to 0 , my weapon not recive shadows from another objects how to fix this?
  20. lordhoban

    lordhoban

    New Member

    Joined:
    Mar 24, 2012
    Messages:
    6
  21. YourSeedyUncle

    YourSeedyUncle

    New Member

    Joined:
    Mar 27, 2012
    Messages:
    8
    This is more of a question than a problem so I didn't make a whole thread. Just wondering, how could I make it say the number of bullets on the hud, instead of showing the bullet pictures? Like this:[​IMG]
  22. TKFiyah

    TKFiyah

    New Member

    Joined:
    Mar 15, 2012
    Messages:
    7
  23. eteeski

    eteeski

    Member

    Joined:
    Feb 2, 2010
    Messages:
    465
    Code (csharp):
    1.  
    2. GUI.Label(ammoCountRect, currentClip.ToString (), " / ", currentExtraAmmo.ToString());
    3.  
  24. iamawesome2

    iamawesome2

    New Member

    Joined:
    Apr 21, 2012
    Messages:
    1
    FPS1.12 Setting the Fire Rate

    when i put in on line 65 cameraObject.GetComponent (MouseLookScript).current AimRacio = 1;

    it says Assets/gunscript.js(65,60): UCE0001: ';' expected. Insert a semicolon at the end.
    Last edited: Apr 21, 2012
  25. SamstA64

    SamstA64

    New Member

    Joined:
    Apr 23, 2012
    Messages:
    1
    Hi,

    For some reason i keep getting this error

    nullreferenceexception object reference not set to an instance of an object

    Code (csharp):
    1. var walkAcceleration : float = 5;
    2. var walkDeacceleration : float = 5;
    3. var cameraObject : GameObject;
    4. var maxWalkSpeed : float = 20;
    5. @HideInInspector
    6. var horizontalMovement : Vector3;
    7.  
    8. var jumpVelocity : float = 800;
    9. @HideInInspector
    10. var grounded : boolean = false;
    11. var maxSlope : float = 60;
    12.  
    13. function Update ()
    14. {
    15.     horizontalMovement = Vector3(rigidbody.velocity.x, 0, rigidbody.velocity.z);
    16.     if(horizontalMovement.magnitude > maxWalkSpeed)
    17.     {
    18.         horizontalMovement = horizontalMovement.normalized;
    19.         horizontalMovement *= maxWalkSpeed;
    20.     }
    21.     rigidbody.velocity.x = horizontalMovement.x;
    22.     rigidbody.velocity.z = horizontalMovement.y;
    23.    
    24.     if(Input.GetAxis("Horizontal") == 0  Input.GetAxis("Vertical") == 0)
    25.     {
    26.         rigidbody.velocity.x /= walkDeacceleration;
    27.         rigidbody.veloctiy.z /= walkDeacceleration;
    28.     }
    29.    
    30.     transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(MouseLookScript).currentYRotation, 0);
    31.     rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration, 0, Input.GetAxis("Vertical") * walkAcceleration);
    32.    
    33.     if(Input.GetButtonDown("Jump")  grounded)
    34.         rigidbody.AddForce(0,jumpVelocity,0);
    35. }
    36.  
    37. function OnCollisionStay (collision : Collision)
    38. {
    39.     for (var contact : ContactPoint in collision.contacts)
    40.     {
    41.         if (Vector3.Angle(contact.normal, Vector3.up) <maxSlope)
    42.             grounded = true;
    43.     }
    44. }
    45.  
    46. function OnCollisionExit ()
    47. {
    48.     grounded = false;
    49. }
  26. LukaKotar

    LukaKotar

    Member

    Joined:
    Sep 25, 2011
    Messages:
    119
    Check if every variable is set up in the inspector.
  27. Snowyblack58

    Snowyblack58

    New Member

    Joined:
    Apr 24, 2012
    Messages:
    4
  28. zzzzz4512

    zzzzz4512

    New Member

    Joined:
    Mar 5, 2011
    Messages:
    7
  29. eteeski

    eteeski

    Member

    Joined:
    Feb 2, 2010
    Messages:
    465
    when you get an error that says "Insert a semicolon at the end" and there is a semicolon at the end, it usually means there is a typo somewhere else in your code. There's probably a squiggly bracket { out of place.
  30. pspkid17

    pspkid17

    New Member

    Joined:
    Dec 13, 2011
    Messages:
    7
  31. JakeGill70

    JakeGill70

    New Member

    Joined:
    May 21, 2012
    Messages:
    6
  32. Zaironn

    Zaironn

    New Member

    Joined:
    Jun 7, 2012
    Messages:
    3
    Hey thanks for the fantastic tutorials and I keep getting the error

    "Assets/MouseLookScript.js(15,53): UCE0001: ';' expected. Insert a semicolon at the end."

    I followed you FPS 1.2 tutorial, and this is what my script looks like so far in the tutorial

    #pragma strict

    var lookSensitivity : float = 5;
    var yRotation : float;
    var xRotation : float;
    var currentYRotation : float;
    var currentXRotation : float;
    var yRotationV : float;
    var xRotationV : float;
    var lookSmoothDamp : float = 0.1;

    function Start () {

    }

    function Update ()
    {
    yRotation += Input.GetAxis("Mouse X") * look Sensitivity;
    xRotation += Input.GetAxis("Mouse Y") * look Sensitivity;

    transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
    }

    Could the #pragma strict or the function start be the problem?
  33. eteeski

    eteeski

    Member

    Joined:
    Feb 2, 2010
    Messages:
    465
    you have a space between "look" and "Sensitivity"
  34. Zaironn

    Zaironn

    New Member

    Joined:
    Jun 7, 2012
    Messages:
    3
    Wow, I'm an idiot lol, thanks keep up the awesome tutorials!!
  35. eteeski

    eteeski

    Member

    Joined:
    Feb 2, 2010
    Messages:
    465
    lol, don't worry about it. 90% of errors are like that :)
  36. Dakattack

    Dakattack

    New Member

    Joined:
    Jun 8, 2012
    Messages:
    2
    Hey there!
    Recently I have been having a problem with walking around and jumping, my character just doesn't want to do anything when I press WSAD or Spacebar! All of your other scripts I have followed have worked fine for me, (like the MouseLookScript) but when I attach the PlayerMovement script to the player capsule, nothing happens, and I get no errors. So then I tried copy pasting your code to see if it was just a silly typo of mine. Still nothing! I made sure the main camera was added to the camera object in the script and I double checked all of the code. I don't now what else to do.

    Thanks in advance,
    Dakota
  37. Minuits2012

    Minuits2012

    New Member

    Joined:
    May 5, 2012
    Messages:
    3
    I went back and started over from FPS1.3 and I get a glitchy jerk on my camera when my player moves idk what the issue is I've looked at both MouseLookScript and even redid the movement script with only the lines from this ep. and have no clue whats going on.
  38. Dakattack

    Dakattack

    New Member

    Joined:
    Jun 8, 2012
    Messages:
    2
    My apologies, I should have read the OP before making a post outside of the criteria.
    I got the problem worked out, kinda. It seemed to be my project folder, because your PlayerMovement Script works fine in any other project I put it in. This can either be a glitch in Unity, or the fact that i am using a flash drive to store my project. Regardless, I had to open a new project and import all of my old assets and place everything in again; A real pain. The only advice I can give to everyone here is to not use an external drive if possible.

    Great tutorials by the way! I have learned so much in just the past week!
    -Dak
  39. n0mi

    n0mi

    New Member

    Joined:
    Jun 11, 2012
    Messages:
    1
    My mouse look script doest work i don't got any error on it so i hope if someone can help me here
    Code (csharp):
    1.  
    2.     var lookSensitivity : float = 5;
    3. @HideInInspector
    4. var yRotation : float;
    5. @HideInInspector
    6. var xRotation : float;
    7. @HideInInspector
    8. var currentYRotation : float;
    9. @HideInInspector
    10. var currentXRotation : float;
    11. @HideInInspector
    12. var yRotationV : float;
    13. @HideInInspector
    14. var xRotationV : float;
    15. var lookSmoothDamp : float = 0.1;
    16.  
    17. function update ()
    18. {
    19.     yRotation += Input.GetAxis("Mouse X") * lookSensitivity;
    20.     xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity;
    21.    
    22.     xRotation = Mathf.Clamp(xRotation, -90, 90);
    23.    
    24.     currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, lookSmoothDamp);
    25.     currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, lookSmoothDamp);
    26.    
    27.     transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
    28. }
    Last edited: Jun 11, 2012
  40. eteeski

    eteeski

    Member

    Joined:
    Feb 2, 2010
    Messages:
    465
    It might be that this line:
    transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
    should be:
    transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
  41. jason201

    jason201

    New Member

    Joined:
    Oct 14, 2011
    Messages:
    122
    I am taking your tutorial and trying to make it run on android. I used your script but when I run it on my phone it only makes one bullet appear I need it to be more like a machine gun. Can you please help me?

    hear is my code


    Code (csharp):
    1.  
    2. var shootButton : GUITexture;
    3. var fireSpeed : float;
    4. var waitTillNextFire : float;
    5. var bullet : GameObject;
    6. var bulletSpawn : GameObject;
    7.  
    8.  
    9.  
    10. function Update()
    11.  
    12. {
    13.  
    14.     var count : int = Input.touchCount;
    15.  
    16.    
    17.  
    18.     for(var i: int = 0;i < count; ++i)//for multi touch
    19.  
    20.     {
    21.  
    22.         var touch : Touch = Input.GetTouch(i);
    23.  
    24.    
    25.  
    26.         if(shootButton.HitTest(touch.position)  touch.phase == TouchPhase.Began)
    27.  
    28.         {
    29.             //Do somthing
    30.             if(waitTillNextFire <= 0)
    31.             {
    32.             if(bullet)
    33.             Instantiate(bullet,bulletSpawn.transform.position, bulletSpawn.transform.rotation);
    34.             waitTillNextFire = 0.1;
    35.            
    36.             }
    37.        
    38.         }
    39.         waitTillNextFire -= Time.deltaTime * fireSpeed;
    40.  
    41.     }
    42.  
    43. }
    44.  
  42. Minuits2012

    Minuits2012

    New Member

    Joined:
    May 5, 2012
    Messages:
    3
    I barely can walk around and when I stop pressing WSAD I continue to move and my camera still jerks around HELP!!!! I've used the scripts as written by you in a different thread and they still wont work correctly
  43. eteeski

    eteeski

    Member

    Joined:
    Feb 2, 2010
    Messages:
    465
    the problem is the touch phase. basically right now, it's like it's set to "GetButtonDown" and you need "GetButton" only in touch form. try this:

    Code (csharp):
    1.  
    2. if(shootButton.HitTest(touch.position))
    3. if ( touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved)
    4. {
    5.           //Do somthing
    6.  
    7.             if(waitTillNextFire <= 0)
    8.  
    9.             {
    10.  
    11.             if(bullet)
    12.  
    13.             Instantiate(bullet,bulletSpawn.transform.position, bulletSpawn.transform.rotation);
    14.  
    15.             waitTillNextFire = 0.1;
    16.  
    17.            
    18.  
    19.             }
    20. }
    21.  
  44. eteeski

    eteeski

    Member

    Joined:
    Feb 2, 2010
    Messages:
    465
    it sounds like you need to play around with the variables in the inspector:
    (PlayerMovementScript)
    walkAcceleration
    walkDeacceleration
    maxWalkSpeed
    (MouseLookScript)
    headbobSpeed
    headbobAmountX
    headbobAmountY
  45. jason201

    jason201

    New Member

    Joined:
    Oct 14, 2011
    Messages:
    122
    It is still not working. Now instead of spawning one bullet its not spawning any.
  46. Cinematronic

    Cinematronic

    New Member

    Joined:
    Oct 22, 2011
    Messages:
    22
    Hello,

    I'm on episode 1.19 Headbob Movement

    The problem is: when I follow the step of fixing the code to avoid the gun glitch, when I change "function Update()" to "function LastUpdate()" in the gunscript, the gun just float on the air without moving or following the player at all.

    My thread: here

    thanks!
    Last edited: Jun 19, 2012
  47. jason201

    jason201

    New Member

    Joined:
    Oct 14, 2011
    Messages:
    122
    thank you for your help I was able to get it to work.
  48. Zaironn

    Zaironn

    New Member

    Joined:
    Jun 7, 2012
    Messages:
    3
    I have watched 1.7 but I'm still slippery, here is my code:

    var walkAcceleration : float = 5;
    var walkAccelAirRatio : float = 0.1;
    var walkDeacceleration : float = 5;
    @HideInInspector
    var walkDeaccelerationVolx : float;
    @HideInInspector
    var walkDeaccelerationVolz : float;
    var cameraObject : GameObject;
    var maxWalkSpeed : float = 20;
    @HideInInspector
    var horizontalMovement : Vector2;
    var jumpVelocity : float = 20;
    @HideInInspector
    var grounded : boolean = false;
    var maxSlope : float = 60;

    function Start () {

    }

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

    rigidbody.velocity.x = horizontalMovement.x;
    rigidbody.velocity.z = horizontalMovement.y;

    if (grounded)
    {
    rigidbody.velocity.x = Mathf.SmoothDamp(rigidbody.velocity.x, 0, walkDeaccelerationVolx, walkDeacceleration);
    rigidbody.velocity.z = Mathf.SmoothDamp(rigidbody.velocity.z, 0, walkDeaccelerationVolz, 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 * walkAccelAirRatio * Time.deltaTime, 0, Input.GetAxis("Vertical") * walkAcceleration * walkAccelAirRatio * 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;
    }

    Please help!
  49. GiORg1

    GiORg1

    New Member

    Joined:
    Jun 25, 2012
    Messages:
    8
    Your tutorials are awsome!I watch your videos FPS.8-FPS.11 and everything ok:gun zoom and etc,but when i am looking down to floor my character jump.i have not bugs in scripts.please help
  50. GiORg1

    GiORg1

    New Member

    Joined:
    Jun 25, 2012
    Messages:
    8