Hello, im following ETeeskiTutorials and im stuck on FPS tutorials 1.23 My problem is when i walk my screen shakes like crazy and ill post scripts so u can see. MouseLookScript Code (csharp): var defaultCameraAngle : float = 60; @HideInInspector var currentTargetCameraAngle : float = 60; @HideInInspector var racioZoom : float = 1; @HideInInspector var racioZoomV : float; var racioZoomSpeed : float = 0.2; var lookSensitivity : float = 5; @HideInInspector var yRotation : float; @HideInInspector var xRotation : float; @HideInInspector var currentYRotation : float; @HideInInspector var currentXRotation : float; @HideInInspector var yRotationV : float; @HideInInspector var xRotationV : float; var lookSmoothDamp : float = 0.1; @HideInInspector var currentAimRacio : float = 1; var headbobSpeed : float = 1; @HideInInspector var headbobStepCounter : float; var headbobAmountX : float = 1; var headbobAmountY : float = 1; @HideInInspector var parentLastPos : Vector3; var eyeHeightRacio : float = 0.9; function Awake () { parentLastPos = transform.parent.position; } function Update () { if (transform.parent.GetComponent(PlayerMovementScript).grounded) headbobStepCounter += Vector3.Distance(parentLastPos, transform.parent.position) * headbobSpeed; transform.localPosition.x = Mathf.Sin(headbobStepCounter) * headbobAmountX * currentAimRacio; transform.localPosition.y = (Mathf.Cos(headbobStepCounter * 2) * headbobAmountY * -1 * currentAimRacio) + (transform.parent.localScale.y * eyeHeightRacio) - (transform.parent.localScale.y / 2); parentLastPos = transform.parent.position; if (currentAimRacio == 1) racioZoom = Mathf.SmoothDamp(racioZoom, 1, racioZoomV, racioZoomSpeed); else racioZoom = Mathf.SmoothDamp(racioZoom, 0, racioZoomV, racioZoomSpeed); camera.fieldOfView = Mathf.Lerp(currentTargetCameraAngle, defaultCameraAngle, racioZoom); yRotation += Input.GetAxis("Mouse X") * lookSensitivity * currentAimRacio; xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity * currentAimRacio; xRotation = Mathf.Clamp(xRotation, -90, 90); currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, lookSmoothDamp); currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, lookSmoothDamp); transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0); } PlayerMovementScript Code (csharp): var currentGun : GameObject; var distToPickUpGun : float = 6; var throwGunUpForce : float = 100; var throwGunForwardForce : float = 300; var waitFrameForSwitchGuns : int = -1; var walkAcceleration : float = 5; var walkAccelAirRacio : 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; var crouchRacio : float = 0.3; var transitionToCrouchSec : float = 0.2; var crouchingVelocity : float; var currentCrouchRacio : float = 1; var originalLocalScaleY : float; var crouchLocalScaleY : float; var collisionDetectionSphere : GameObject; function Awake () { currentCrouchRacio = 1; originalLocalScaleY = transform.localScale.y; crouchLocalScaleY = transform.localScale.y * crouchRacio; } function LateUpdate () { waitFrameForSwitchGuns -= 1; transform.localScale.y = Mathf.Lerp(crouchLocalScaleY, originalLocalScaleY, currentCrouchRacio); if (Input.GetButton("Crouch")) currentCrouchRacio = Mathf.SmoothDamp(currentCrouchRacio, 0, crouchingVelocity, transitionToCrouchSec); if (Input.GetButton("Crouch") == false collisionDetectionSphere.GetComponent(CollisionDetectionSphereScript).collisionDetected == false) currentCrouchRacio = Mathf.SmoothDamp(currentCrouchRacio, 1, crouchingVelocity, transitionToCrouchSec); 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 * walkAccelAirRacio * Time.deltaTime, 0, Input.GetAxis("Vertical") * walkAcceleration * walkAccelAirRacio * 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; } GunScript Code (csharp): var beingHeld : boolean = false; var outsideBox : GameObject; @HideInInspector var countToThrow : int = -1; @HideInInspector var playerTransform : Transform; @HideInInspector var playerMovementScript : PlayerMovementScript; @HideInInspector 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; var aimRacio : float = 0.4; var zoomAngle : float = 30; var fireSpeed : float = 15; @HideInInspector var waitTilNextFire : float = 0; var bullet : GameObject; var bulletSpawn : GameObject; var shootAngleRandomizationAiming : float = 5; var shootAngleRandomizationNotAiming : float = 15; var recoilAmount : float = 0.5; var recoilRecoverTime : float = 0.2; @HideInInspector var currentRecoilZPos : float; @HideInInspector var currentRecoilZPosV : float; var bulletSound : GameObject; var muzzelFlash : GameObject; var gunbobAmountX : float = 0.5; var gunbobAmountY : float = 0.5; var currentGunbobX : float; var currentGunbobY : float; function Awake () { countToThrow = -1; playerTransform = GameObject.FindWithTag("Player").transform; playerMovementScript = GameObject.FindWithTag("Player").GetComponent(PlayerMovementScript); cameraObject = GameObject.FindWithTag("MainCamera"); } function LateUpdate () { if (beingHeld) { rigidbody.useGravity = false; outsideBox.GetComponent(Collider).enabled = false; currentGunbobX = Mathf.Sin(cameraObject.GetComponent(MouseLookScript).headbobStepCounter) * gunbobAmountX * racioHipHold; currentGunbobY = Mathf.Cos(cameraObject.GetComponent(MouseLookScript).headbobStepCounter * 2) * gunbobAmountY * -1 * racioHipHold; var holdMuzzelFlash : GameObject; var holdSound : GameObject; if (Input.GetButton("Fire1")) { if (waitTilNextFire <= 0) { if (bullet) Instantiate(bullet,bulletSpawn.transform.position, bulletSpawn.transform.rotation); if (bulletSound) holdSound = Instantiate(bulletSound, bulletSpawn.transform.position, bulletSpawn.transform.rotation); if (muzzelFlash) holdMuzzelFlash = Instantiate(muzzelFlash, bulletSpawn.transform.position, bulletSpawn.transform.rotation); targetXRotation += (Random.value - 0.5) * Mathf.Lerp(shootAngleRandomizationAiming, shootAngleRandomizationNotAiming, racioHipHold); targetYRotation += (Random.value - 0.5) * Mathf.Lerp(shootAngleRandomizationAiming, shootAngleRandomizationNotAiming, racioHipHold); currentRecoilZPos -= recoilAmount; waitTilNextFire = 1; } } waitTilNextFire -= Time.deltaTime * fireSpeed; if (holdSound) holdSound.transform.parent = transform; if (holdMuzzelFlash) holdMuzzelFlash.transform.parent = transform; currentRecoilZPos = Mathf.SmoothDamp( currentRecoilZPos, 0, currentRecoilZPosV, recoilRecoverTime); cameraObject.GetComponent(MouseLookScript).currentTargetCameraAngle = zoomAngle; if (Input.GetButton("Fire2")){ cameraObject.GetComponent(MouseLookScript).currentAimRacio = aimRacio; racioHipHold = Mathf.SmoothDamp(racioHipHold, 0, racioHipHoldV, hipToAimSpeed);} if (Input.GetButton("Fire2") == false){ cameraObject.GetComponent(MouseLookScript).currentAimRacio = 1; racioHipHold = Mathf.SmoothDamp(racioHipHold, 1, racioHipHoldV, hipToAimSpeed);} transform.position = cameraObject.transform.position + (Quaternion.Euler(0,targetYRotation,0) * Vector3(holdSide * racioHipHold + currentGunbobX, holdHeight * racioHipHold + currentGunbobY, 0) + Quaternion.Euler(targetXRotation, targetYRotation, 0) * Vector3(0,0,currentRecoilZPos)); 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 (!beingHeld) { rigidbody.useGravity = true; outsideBox.GetComponent(Collider).enabled = true; countToThrow -= 1; if (countToThrow == 0) rigidbody.AddRelativeForce(0, playerMovementScript.throwGunUpForce, playerMovementScript.throwGunForwardForce); if (Vector3.Distance(transform.position, playerTransform.position) < playerMovementScript.distToPickUpGun Input.GetButtonDown("Use Key") playerMovementScript.waitFrameForSwitchGuns <= 0) { playerMovementScript.currentGun.GetComponent(GunScript).beingHeld = false; playerMovementScript.currentGun.GetComponent(GunScript).countToThrow = 2; playerMovementScript.currentGun = gameObject; beingHeld = true; targetYRotation = cameraObject.GetComponent(MouseLookScript).yRotation - 180; playerMovementScript.waitFrameForSwitchGuns = 2; } } } Any help would be really nice
go to his youtube channel and watch one of his latest videos. he started a new thread on this forum for those who are following his tutorials who get stuck to find help. Check it out and i bet you'll find an answer.
lol that's exactly what he did the way it's supposed to work is that everyone will post links to their thread in my thread so everyone can find each other's threads.
Does the screen start shaking when you first start the game or only once you switch a gun? Does it shake when you are standing still, walking, jumping, switching back to the last gun, ect.?
And the outsideBox is assigned in the inspector and is the only collider attached to the gun (or at least the only collider that isn't set to isTrigger)?
The screen doesnt shake when i start the game and it doesnt matter which gun im holding it only shakes when im walking and when i walk a bit then jump, then it will shake
weird. is there a rigidbody attached to your camera? and is the position and rotation frozen on the rigidbody of the capsule? all three x,y, and z?
yes rigidbody was on but the position wasnt frozen, not sure y it was working before then. But thank you so much
Assets/scripts/Gun.cs(1,23): error CS8025: Parsing error Assets/scripts/Mouselook.cs(1,24): error CS8025: Parsing error Assets/scripts/PlayerMove.cs(1,16): error CS8025: Parsing error I have this Errors , can you help my ? Please