Search Unity

  1. 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. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    Have you tried moving the bullet script to LateUpdate, and the GunScript to Update?

    If that doesn't fix it, plug this line of code into your bullet's awake function

    This will pause the game. Then, post a picture with the bullet selected, and one with the bullet spawn selected. I need a little more info. :)
     
  2. td456

    td456

    Joined:
    Jan 13, 2013
    Posts:
    5
    On 1.8 I have a problem where when I spawn, the gun is behind my character, not in front so I can't see it. I have the holdHeight and holdSide set correctly but the gun spawns behind the character. Is there a way to add a variable so you can set the position of the gun being in front of the character or behind the character? If you can help that would be great.

    Thanks
     
  3. td456

    td456

    Joined:
    Jan 13, 2013
    Posts:
    5
    These tutorials are great!
     
    Last edited: Jan 16, 2013
  4. Tea_Doogun

    Tea_Doogun

    Joined:
    Jul 16, 2012
    Posts:
    9
  5. td456

    td456

    Joined:
    Jan 13, 2013
    Posts:
    5
    FPS 1.8 Basic Gun with Weight.

    Hi I came across a problem where when I look up and down on my game, the gun goes the opposite way im looking. When I look down, the gun goes up, and when I look up, the gun goes down. Can you please help me? Thank you.
     
    Last edited: Jan 16, 2013
  6. tictactokyo

    tictactokyo

    Joined:
    Jan 17, 2013
    Posts:
    1
    i have the same problem but i did not use a flash drive infact i started a new project just for this tutorial
    any information will be helpfull
     
  7. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    Can you post you code?
     
  8. jose94ji

    jose94ji

    Joined:
    Jan 15, 2013
    Posts:
    2
    I keep getting an error message for line 12 and have no idea what is wrong in the script
    Assets/Scripts/PlayerMovementScript.js(12,24): BCE0044: expecting :, found '='.
     
  9. jose94ji

    jose94ji

    Joined:
    Jan 15, 2013
    Posts:
    2
    var walkAcceleration : float = 5;
    var cameraObject : GameObject;
    var maxWalkSpeed : float = 20;
    @HideInInspector
    var horizontalMovement : Vector2;

    function Update ()
    {
    horizontalMovement = Vector2( rigidbody.velocity.x, rigidbody.velocity.z);
    if (horizontalMovement.magnitude > maxWalkSpeed);
    {
    horizontalMovement = horizontalMovement.normalized;
    horizantalMovement *= maxWalkSpeed;
    }
    rigidbody.horizontalMovement.x = horizontalMovement.x;
    rigidbody.horizontalMovement.z = horizontalMovement.y;
    transform.rotation = Quaternion.Euler(0,cameraObject.GetComponent(MouseLookScript).currentYRotation,0);
    rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration, 0, Input.GetAxis("Vertical") * walkAcceleration);
    }


    Thats my script, but i keep getting
    Assets/Scripts/PlayerMovementScript.js(12,36): BCE0044: expecting :, found '='.
    CAn someone help ASAP please??
     
  10. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    At the line

    -
    Code (csharp):
    1. rigidbody.AddRelativeForce(Input.GetAxis("Horizont al") * walkAcceleration, 0, Input.GetAxis("Vertical") *
    You have a space in the word horizontal, Make it:

    Code (csharp):
    1. rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration, 0, Input.GetAxis("Vertical") *
     
  11. td456

    td456

    Joined:
    Jan 13, 2013
    Posts:
    5
    Here is my code

    var cameraObject : GameObject;
    var targetXRotation : float;
    var targetYRotation : float;
    var targetXRotationV : float;
    var targetYRotationV : float;
    var rotateSpeed : 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, 2.5));

    targetXRotation = Mathf.SmoothDamp( targetXRotation, cameraObject.GetComponent(MouseLookScript).xRotation, targetXRotationV, rotateSpeed);
    targetYRotation = Mathf.SmoothDamp( targetYRotation, cameraObject.GetComponent(MouseLookScript).yRotation, targetYRotationV, rotateSpeed);

    transform.rotation = Quaternion.Euler(targetXRotation, targetYRotation, 0);

    }
     
  12. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    Okay, how about:
    Code (csharp):
    1.  
    2. var cameraObject : GameObject;
    3. var targetXRotation : float;
    4. var targetYRotation : float;
    5. var targetXRotationV : float;
    6. var targetYRotationV : float;
    7. var rotateSpeed : float = 0.3;
    8.  
    9. var holdHeight : float = -0.5;
    10. var holdSide : float = 0.5;
    11.  
    12.  
    13. function Update()
    14. {
    15. transform.position = cameraObject.transform.position + (Quaternion.Euler(0,targetYRotation,0) * Vector3(holdSide, holdHeight, 2.5));
    16.  
    17. targetXRotation = Mathf.SmoothDamp( targetXRotation, cameraObject.GetComponent(MouseLookScript).xRotation, targetXRotationV, rotateSpeed);
    18. targetYRotation = Mathf.SmoothDamp( targetYRotation, cameraObject.GetComponent(MouseLookScript).yRotation, targetYRotationV, rotateSpeed);
    19.  
    20. transform.rotation = Quaternion.Euler(-targetXRotation, -targetYRotation, 0);
    21.  
    22. }
     
  13. ic3t3a2000

    ic3t3a2000

    Joined:
    Dec 15, 2012
    Posts:
    3
    I am on FPS 1.39 and everything almost functions correctly. However my "enemy body" is below the ground. Its not floating on the top of the AIpathCell. If I move the AIpathCell height then I can make it line up with the ground but this is not ideal. Any idea what I might be doing wrong? Below is the code.

    var moveDamp : float = 0.1;
    var parentToFollow : Transform;
    var parentLastPos : Vector3;
    var targetRotation : Quaternion;
    var turnSpeed : float = 10;

    var velocityX : float;
    var velocityZ : float;

    function Awake ()
    {
    parentToFollow = transform.parent;
    transform.parent = null;
    }

    function Update ()
    {
    transform.position.x = Mathf.SmoothDamp(transform.position.x, parentToFollow.position.x, velocityX, moveDamp);
    transform.position.z = Mathf.SmoothDamp(transform.position.z, parentToFollow.position.z, velocityZ, moveDamp);

    var tempParentCurrentPos : Vector3 = parentToFollow.position;
    var tempParentLastPos : Vector3 = parentLastPos;
    tempParentCurrentPos.y = 0;
    tempParentLastPos.y = 0;

    targetRotation = Quaternion.LookRotation(tempParentCurrentPos - tempParentLastPos);
    parentLastPos = parentToFollow.position;

    transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, turnSpeed * Time.deltaTime);

    var hits : RaycastHit[];
    hits = Physics.RaycastAll(Ray(transform.position + Vector3(0,100,0), Vector3.up * -1));
    for (var i : int = 0; i < hits.length; i++)
    {
    var hit : RaycastHit = hits;
    if (hit.transform.gameObject == parentToFollow.gameObject.GetComponent(EnemyMovementScript).currentCell)
    transform.position.y = hit.point.y;
    }
    }
     
  14. td456

    td456

    Joined:
    Jan 13, 2013
    Posts:
    5
    That did not help either. When I look around, the gun spins out of the character and positions itself somewhere else. Sorry for bugging you.
     
  15. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    Is your gun a child of the camera? If it is, unchild it, and revert back to your original code.
     
  16. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818


    Is the enemy body script attached to the actual enemy mesh? If it is, make the enemybody it's own separate gameObject, and make the mesh a child of that object. Then, move it so it's feet line up with the base of the enemy body.
     
  17. ic3t3a2000

    ic3t3a2000

    Joined:
    Dec 15, 2012
    Posts:
    3
    Thanks that did the trick.
     
  18. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    Awesome!
     
  19. FutureGameEngine

    FutureGameEngine

    Joined:
    Jan 22, 2013
    Posts:
    8
  20. Warb

    Warb

    Joined:
    Feb 3, 2013
    Posts:
    2
  21. FutureGameEngine

    FutureGameEngine

    Joined:
    Jan 22, 2013
    Posts:
    8
  22. FirePlantGames

    FirePlantGames

    Joined:
    Dec 11, 2012
    Posts:
    49
  23. omgitskara

    omgitskara

    Joined:
    Jan 26, 2013
    Posts:
    9
  24. FirePlantGames

    FirePlantGames

    Joined:
    Dec 11, 2012
    Posts:
    49
  25. Maimo

    Maimo

    Joined:
    Feb 14, 2013
    Posts:
    3
    FPS 1.30 opening Doors...

    im having a problem with the doors you did in fps1.30... see the thread link below, thanx

    http://forum.unity3d.com/threads/170925-ETeeskiTutorials-FPS-1.30-Opening-and-Closing-Doors-issue-with-copies-and-prefabs?p=1168559#post1168559

    this door tutorial is great... Works well, but when i try and make copies of the door (or prefabs) and place them in a new scene only doors near the original placed door open, if i move them to far away from the first door they stop working... cant figure it out... does each one need to have a unique button name for the button transform? i was doing them as prefabs.


    also.... GREAT JOB on the tutorials!!! i'm a teacher for middle and high-school students and i love your tutorials, I want to start teaching kids unity and your tutorials are great! I especially like you dont swear on camera... that makes it appropriate for all audiences. there are so many tutorials on youtube that i cant show kids due to language. Thanks again.
     
    Last edited: Feb 18, 2013
  26. Dragonkkealk

    Dragonkkealk

    Joined:
    Feb 23, 2013
    Posts:
    17
    Last edited: Feb 25, 2013
  27. TheNachoman180

    TheNachoman180

    Joined:
    Feb 18, 2013
    Posts:
    7
    FPS1.12

    My Gun is innacurate and shoots to the left of the middle of the screen but the gameobject is perfectly on the end of the gun. (The gun points in the middle of the screen)
     
  28. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    It's not a glitch. It's a result of the bullet shooting from the gun rather from the camera.
     
  29. TheNachoman180

    TheNachoman180

    Joined:
    Feb 18, 2013
    Posts:
    7
    but the gun is exactly in the middle of the screen while aiming

    also, when i attach it to the camera and set the xyz to 000 it still shoots to the top left
     
    Last edited: Mar 1, 2013
  30. Trikstamachine

    Trikstamachine

    Joined:
    Mar 2, 2013
    Posts:
    9
    In Episode 1.4 and 1.3, my cylinder will not move. My code is exactly like yours except it is giving me errors, errors that you don't have. I have even tried to Copy and Paste the PlayerMovementScript code you posted, and it didn't work either....please help. This is my code so far:



    var walkAcceleration : float = 5;
    var cameraObject : GameObject;
    var maxWalkSpeed : float = 20;
    @HideInInspector
    var horizantalMovement = Vector2;

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

    transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(MouseLookScript).currentYRotation, 0);
    rigidbody.AddRelativeForce(Input.GetAxis("Horizantal") * walkAcceleration, 0, Input.GetAxis("Vertical") * walkAcceleration);
    }
     
  31. Spot75

    Spot75

    Joined:
    Mar 2, 2013
    Posts:
    2
    I am just learning too but managed to spot two things. horizantal should be spelled horizontal, and where you have "horizantalMovement.normalized;" I wrote horizontalMovement.normalize(); and it worked for me. Good Luck .
     
  32. TheNachoman180

    TheNachoman180

    Joined:
    Feb 18, 2013
    Posts:
    7
    -.- Tried to fix for ages. Any ideas guys? I can send a screenshot
     
  33. Trikstamachine

    Trikstamachine

    Joined:
    Mar 2, 2013
    Posts:
    9
    Thanks!! It works now!
     
  34. Spot75

    Spot75

    Joined:
    Mar 2, 2013
    Posts:
    2
    Glad I could help. Eteeski Rules!! Peace!!
     
  35. TheNachoman180

    TheNachoman180

    Joined:
    Feb 18, 2013
    Posts:
    7
    Hello, is it possible to make a different buletscript for buckshot shotguns? Like multiple raycasts randomly positioned in a certain area? Also i still need to fix my raycast accuracy -.- (look up)
     
  36. Trikstamachine

    Trikstamachine

    Joined:
    Mar 2, 2013
    Posts:
    9
    My "gun" which is a cube model like yours (episode 1.8) is falling through the floor and won't stop. I don't know what is wrong with it... this is my code:


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

    var rotateSpeed : float = 0.3;

    var holdHeight : float = -0.5;
    var holdSide : float = 0.5;

    function Update ()
    {
    transform.position = gameObject.transform.position + (Quaternion.Euler(0,targetYRotation,0) * Vector3(holdSide, holdHeight, 0));

    targetXRotation = Mathf.SmoothDamp( targetXRotation, cameraObject.GetComponent(MouseLookScript).xRotation, targetXRotationV, rotateSpeed);
    targetYRotation = Mathf.SmoothDamp( targetYRotation, cameraObject.GetComponent(MouseLookScript).yRotation, targetYRotationV, rotateSpeed);

    transform.rotation = Quaternion.Euler(targetXRotation, targetYRotation, 0);
    }
     
  37. TheNachoman180

    TheNachoman180

    Joined:
    Feb 18, 2013
    Posts:
    7
    did you make an outsidebox with a collider? Did you attach that box to the gun?
     
  38. Trikstamachine

    Trikstamachine

    Joined:
    Mar 2, 2013
    Posts:
    9
    Well, ETeeski turned the box collider off..I did the same as him. I tried with the collider on and it still fell through the world. IT JUST WON'T STAY ON CAPSULE :(
    Please help :(...if it helps with my problem, I made a new project and tried it with a preset gun I downloaded from the Asset Store and it worked fine :/.
     
  39. TheNachoman180

    TheNachoman180

    Joined:
    Feb 18, 2013
    Posts:
    7
    maybe have a look at the downloaded gun vs your gun. check the differences
     
  40. Trikstamachine

    Trikstamachine

    Joined:
    Mar 2, 2013
    Posts:
    9
    I will.. but do you know how to fix it? My code is fine right?
     
  41. Trikstamachine

    Trikstamachine

    Joined:
    Mar 2, 2013
    Posts:
    9
    It has no script on it. when i added the gun script to the weapon it just fell through the map like my other project...i am not sure what is wrong
    Can anyone help?
     
  42. TheNachoman180

    TheNachoman180

    Joined:
    Feb 18, 2013
    Posts:
    7
    So your terrain and your player capsule have colliders and there working fine? Ill say again make sure you have a box collider with collision ticked on your gun. It will be a cube/rectangle and you position it and attach it to the gun then the box will collide with the terrain. Well it should anyway. And yes your code is fine. most of those colliders and stuff arent used in code
     
  43. Trikstamachine

    Trikstamachine

    Joined:
    Mar 2, 2013
    Posts:
    9
    In Unity it is sayin "NullReferenceException: Object reference not set to an instance of an object"
    I am not sure what this means. My code looks fine too...

    var floatAbove : float = 0.1;
    var playerCapsuleTransform : Transform;
    @HideInInspector
    var collisionDetected : boolean = false;

    function Update ()
    {
    transform.position.x = playerCapsuleTransform.position.x;
    transform.position.z = playerCapsuleTransform.position.z;
    transform.position.y = playerCapsuleTransform.position.y + ((playerCapsuleTransform.GetComponent(Collider.height * playerCapsuleTransform.localScale.y) / 2) + (transform.localScale.y / 2) + floatAbove);
    }

    function OnCollisionStay (collision : Collision)
    {
    if (collision.transform.tag == "Level Parts");
    collisionDetected = true;
    }

    function OnCollisionExit ()
    {
    collisionDetected = false;
    }
     
  44. Trikstamachine

    Trikstamachine

    Joined:
    Mar 2, 2013
    Posts:
    9
  45. Serapsi

    Serapsi

    Joined:
    Mar 10, 2013
    Posts:
    2
    FPS 1.5 Jumping the Right Way

    For some reason, my capsule will shudder slightly when I press the spacebar, but it will not jump more than 0.004 units above where it lands on the cube floor. The code is as follows:

    var walkAcceleration : float = 5;
    var cameraObject : GameObject;
    var maxWalkSpeed : float = 20;
    var horizontalMovement : Vector2;
    var jumpVelocity : float = 200;
    var grounded : boolean = false;
    var maxSlope : float = 60;

    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;
    transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(RotateCamera).currentYRotation,0);
    rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration, 0, Input.GetAxis("Vertical") * walkAcceleration);

    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;
    }

    Any ideas? Thanks
     
  46. Serapsi

    Serapsi

    Joined:
    Mar 10, 2013
    Posts:
    2
    I made a new project, brought in the scripts, did everything the same and now jumping somehow works. The old project still doesn't work, but jumping in the new project works fine. No idea how I fixed it, but it is fixed, so you can ignore my previous post.
     
  47. feimex

    feimex

    Joined:
    Mar 11, 2013
    Posts:
    2
  48. SubjectSix

    SubjectSix

    Joined:
    Mar 12, 2013
    Posts:
    6
    FPS1.9

    I have a, I wouldn't say glitch, but something strange.
    When I right click to aim in. The gun moves closer to my face and that's it
    Please help!
    Gun Script:

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

    var rotateSpeed : float = 0.3;

    var holdHeight : float = -0.5;
    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, rotateSpeed);
    targetYRotation = Mathf.SmoothDamp( targetYRotation, cameraObject.GetComponent(MouseLookScript).yRotation, targetYRotationV, rotateSpeed);

    transform.rotation = Quaternion.Euler(targetXRotation, targetYRotation, 0);
    }

    If you need images i'll post some.
     
  49. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    If you could post images of the problem, as well as of the gun's hierarchy and aiming cube, that would be a HUGE help. :)
     
  50. SubjectSix

    SubjectSix

    Joined:
    Mar 12, 2013
    Posts:
    6