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

ETeeskiTutorials FPS1 Problem Diagnostic Collaboration Thread

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

  1. eteeski

    eteeski

    Joined:
    Feb 2, 2010
    Posts:
    476
    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

    Joined:
    Jul 22, 2010
    Posts:
    82
    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

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

    GeekFreek

    Joined:
    Mar 7, 2012
    Posts:
    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

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

    vipvex

    Joined:
    Dec 6, 2011
    Posts:
    72
  7. equalspotato

    equalspotato

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

    TKFiyah

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

    Squall Leonhart

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

    Squall Leonhart

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

    CameronCBTV

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

    hijsm

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

    lordhoban

    Joined:
    Mar 24, 2012
    Posts:
    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

    Joined:
    Mar 27, 2012
    Posts:
    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

    Joined:
    Mar 28, 2012
    Posts:
    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. jbecana

    jbecana

    Joined:
    Feb 14, 2012
    Posts:
    22
    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

    Joined:
    Mar 28, 2012
    Posts:
    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

    Joined:
    Jan 13, 2012
    Posts:
    143
    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 = myTransform.TransformDirection(targetVelocity);
    60.         targetVelocity *= speed;   
    61.        
    62.         // Apply a force that attempts to reach our target velocity
    63.         var velocity = rigidbody.velocity;
    64.         var velocityChange = (targetVelocity - velocity);
    65.         velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
    66.         velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
    67.         velocityChange.y = 0;
    68.         rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);
    69.    
    70.        
    71.         if (canJump  Input.GetButton("Jump")){
    72.             rigidbody.velocity = Vector3(velocity.x, CalculateJumpVerticalSpeed(), velocity.z);
    73.         }
    74.        
    75.         if(!crouching){
    76.             if (grounded  Input.GetButton("Run")  Input.GetKey("w"))
    77.                 speed = runSpeed;
    78.                 else
    79.                 speed = walkSpeed;
    80.             }else{
    81.             speed = crouchSpeed;
    82.         }
    83.    
    84.     }else{
    85.    
    86.         // AirControl
    87.         targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
    88.         targetVelocity = transform.TransformDirection(targetVelocity) * inAirControl;
    89.         rigidbody.AddForce(targetVelocity, ForceMode.VelocityChange);
    90.     }
    91.  
    92.     // Gravity
    93.     rigidbody.AddForce(Vector3 (0, -gravity * rigidbody.mass, 0));
    94.     grounded = false;
    95. }
    96.  
    97. function OnCollisionStay (col : Collision){
    98.     if (Physics.Raycast(myTransform.position, -Vector3.up, hit, rayDistance)) {
    99.         grounded = true;
    100.     }  
    101. }
    102.  
    103. function HitJumpPad(velocity: float) {
    104.        rigidbody.velocity.z += velocity;
    105.     }
    106.  
    107. function OnCollisionEnter (collision : Collision){
    108.     if(!grounded){
    109.         fallAnimGO.animation.CrossFadeQueued("Fall", 0.3, QueueMode.PlayNow);
    110.         var currSpeed : float = collision.relativeVelocity.magnitude;
    111.        
    112.         if (currSpeed > 20) {
    113.             var damage : float = currSpeed * fallDamageMultiplier;
    114.             Debug.Log ("FallDamage" + damage);
    115.             SendMessage ("PlayerDamage", damage, SendMessageOptions.DontRequireReceiver);
    116.         }  
    117.     }  
    118. }
    119.  
    120. function CalculateJumpVerticalSpeed (){
    121.     return Mathf.Sqrt(2 * jumpHeight * gravity);
    122. }
    123.  
    124. function Update(){
    125.  
    126.     if (grounded  rigidbody.velocity.magnitude < (walkSpeed+2)  rigidbody.velocity.magnitude > (walkSpeed-2)  !Input.GetButton("Fire2")){
    127.         playerWeapons.animation.CrossFade("Walk");
    128.        
    129.     }else if (grounded  rigidbody.velocity.magnitude < (runSpeed+2)  rigidbody.velocity.magnitude > (runSpeed -2)){
    130.         playerWeapons.animation.CrossFade("Run");
    131.        
    132.     }else if (grounded  rigidbody.velocity.magnitude < (crouchSpeed+1)  rigidbody.velocity.magnitude > (crouchSpeed-1)  Input.GetButton("Fire2"))
    133.         playerWeapons.animation.CrossFade("CrouchAim");
    134.    
    135.     else
    136.         playerWeapons.animation.CrossFade("IdleAnim");
    137.        
    138.    
    139.     if(mainCameraGO.transform.localPosition.y > normalHeight){
    140.         mainCameraGO.transform.localPosition.y = normalHeight;
    141.     } else if(mainCameraGO.transform.localPosition.y < crouchHeight){
    142.         mainCameraGO.transform.localPosition.y = crouchHeight;
    143.     }
    144.    
    145.     if(weaponCameraGO.transform.localPosition.y > normalHeight){
    146.         weaponCameraGO.transform.localPosition.y = normalHeight;
    147.     } else if(weaponCameraGO.transform.localPosition.y < crouchHeight){
    148.         weaponCameraGO.transform.localPosition.y = crouchHeight;
    149.     }
    150.    
    151.     if (Input.GetButtonDown("Crouch")  !crouching) {
    152.         collider.height = 1.5;
    153.         collider.center = Vector3 (0, -0.25, 0);
    154.         crouching = true;
    155.     }
    156.  
    157.     if(Input.GetButtonUp("Crouch")  crouching){
    158.         collider.height = 2.0;
    159.         collider.center = Vector3 (0, 0, 0);
    160.         crouching = false;
    161.     }
    162.    
    163.     if(crouching){
    164.         if(mainCameraGO.transform.localPosition.y > crouchHeight){
    165.             if(mainCameraGO.transform.localPosition.y - (crouchingHeight * Time.deltaTime/.1) < crouchHeight){
    166.                 mainCameraGO.transform.localPosition.y = crouchHeight;
    167.             } else {
    168.                 mainCameraGO.transform.localPosition.y -= crouchingHeight * Time.deltaTime/.1;
    169.             }
    170.         }
    171.         if(weaponCameraGO.transform.localPosition.y > crouchHeight){
    172.             if(weaponCameraGO.transform.localPosition.y - (crouchingHeight * Time.deltaTime/.1) < crouchHeight){
    173.                 weaponCameraGO.transform.localPosition.y = crouchHeight;
    174.             } else {
    175.                 weaponCameraGO.transform.localPosition.y -= crouchingHeight * Time.deltaTime/.1;
    176.             }
    177.         }
    178.  
    179.     } else {
    180.         if(mainCameraGO.transform.localPosition.y < normalHeight){
    181.             if(mainCameraGO.transform.localPosition.y + (crouchingHeight * Time.deltaTime/.1) > normalHeight){
    182.                 mainCameraGO.transform.localPosition.y = normalHeight;
    183.             } else {
    184.                 mainCameraGO.transform.localPosition.y += crouchingHeight * Time.deltaTime/.1;
    185.             }
    186.         }
    187.         if(weaponCameraGO.transform.localPosition.y < normalHeight){
    188.             if(weaponCameraGO.transform.localPosition.y + (crouchingHeight * Time.deltaTime/.1) > normalHeight){
    189.                 weaponCameraGO.transform.localPosition.y = normalHeight;
    190.             } else {
    191.                 weaponCameraGO.transform.localPosition.y += crouchingHeight * Time.deltaTime/.1;
    192.             }
    193.         }
    194.     }
    195. }
    196.  
    197. function Accelerate (accelerateY : float, accelerateZ : float){
    198.     grounded = false;
    199.     rigidbody.AddRelativeForce (0, accelerateY, accelerateZ);  
    200. }
     
  19. Deki3d

    Deki3d

    Joined:
    Feb 20, 2012
    Posts:
    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

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

    YourSeedyUncle

    Joined:
    Mar 27, 2012
    Posts:
    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:
     
  22. TKFiyah

    TKFiyah

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

    eteeski

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

    iamawesome2

    Joined:
    Apr 21, 2012
    Posts:
    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

    Joined:
    Apr 23, 2012
    Posts:
    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

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

    Snowyblack58

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

    zzzzz4512

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

    eteeski

    Joined:
    Feb 2, 2010
    Posts:
    476
    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

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

    JakeGill70

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

    Zaironn

    Joined:
    Jun 7, 2012
    Posts:
    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

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

    Zaironn

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

    eteeski

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

    Dakattack

    Joined:
    Jun 8, 2012
    Posts:
    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

    Joined:
    May 5, 2012
    Posts:
    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

    Joined:
    Jun 8, 2012
    Posts:
    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

    Joined:
    Jun 11, 2012
    Posts:
    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

    Joined:
    Feb 2, 2010
    Posts:
    476
    It might be that this line:
    transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
    should be:
    transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
     
  41. djc-smithers

    djc-smithers

    Joined:
    Oct 14, 2011
    Posts:
    123
    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

    Joined:
    May 5, 2012
    Posts:
    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

    Joined:
    Feb 2, 2010
    Posts:
    476
    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

    Joined:
    Feb 2, 2010
    Posts:
    476
    it sounds like you need to play around with the variables in the inspector:
    (PlayerMovementScript)
    walkAcceleration
    walkDeacceleration
    maxWalkSpeed
    (MouseLookScript)
    headbobSpeed
    headbobAmountX
    headbobAmountY
     
  45. djc-smithers

    djc-smithers

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

    Cinematronic

    Joined:
    Oct 22, 2011
    Posts:
    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. djc-smithers

    djc-smithers

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

    Zaironn

    Joined:
    Jun 7, 2012
    Posts:
    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. Zwero

    Zwero

    Joined:
    Jun 26, 2012
    Posts:
    7
    Solved
     
    Last edited: Jun 26, 2012
  50. Zwero

    Zwero

    Joined:
    Jun 26, 2012
    Posts:
    7
    Last edited: Jun 27, 2012