asebotropical.blogg.se

How To Go Third Person In Gmod
how to go third person in gmod

























Also when I sit in seats it puts my model into 3rd person view and I cant see anything but his back. How do i get out of 3rd person view when in vehicles, I want 1st person view so I can see ahead of me. Stuck in 3rd Person while driving - A Forum Thread for Garrys Mod.

how to go third person in gmod

Remove Capsule Collider component from Capsule and change its position to (0, 1, 0) Create new Capsule (Game Object -> 3D Object -> Capsule) and move it inside "Player" Object Create a new Game Object (Game Object -> Create Empty) and name it "Player"

Go Third Person In Gmod Code Below Inside

Gravity is multiplied by deltaTime twice (once here, and once below// when the moveDirection is multiplied by deltaTime). Create a new Script and call it SC_TPSController and paste the code below inside it:Public class SC_TPSController : MonoBehaviour// We are grounded, so recalculate move direction based on axesVector3 forward = transform.TransformDirection(Vector3.forward) Vector3 right = transform.TransformDirection(Vector3.right) Float curSpeedX = canMove ? speed * Input.GetAxis("Vertical") : 0 Float curSpeedY = canMove ? speed * Input.GetAxis("Horizontal") : 0 MoveDirection = (forward * curSpeedX) + (right * curSpeedY) // Apply gravity. Move the Main Camera inside "CameraParent" Object and move it behind the Player (In my case I moved it to this position: (0.5, 0.6, -2.9))

Tweak Collision Offset and Camera Speed values if the Camera is clipping through the wallsThe TPS Camera is now ready, press Play to test it. Assign CameraParent to Reference Transform variable Attach SC_CameraCollision to Main Camera Create a new script, name it SC_CameraCollision then paste the code below inside it:Public class SC_CameraCollision : MonoBehaviourPublic float collisionOffset = 0.3f //To prevent Camera from clipping through ObjectsPublic float cameraSpeed = 15f //How fast the Camera should snap into position if there are no obstacles// Start is called before the first frame updateDirectionNormalized = defaultPos.normalized DefaultDistance = Vector3.Distance(defaultPos, Vector3.zero) Cursor.lockState = CursorLockMode.Locked Vector3 dirTmp = parentTransform.TransformPoint(defaultPos) - referenceTransform.position If (Physics.SphereCast(referenceTransform.position, collisionOffset, dirTmp, out hit, defaultDistance))CurrentPos = (directionNormalized * (hit.distance - collisionOffset)) Transform.localPosition = Vector3.Lerp(transform.localPosition, currentPos, Time.deltaTime * cameraSpeed) Assign "CameraParent" Object to playerCameraParent variableCamera collision detection will consist of a script that will check if there is anything between the Camera and the Player, and will automatically move the Camera closer, thus preventing the Camera from clipping through the objects. Attach SC_TPSController script to "Player" Object (You will notice that it also added another component called Character Controller, change its center value to (0, 1, 0))

how to go third person in gmod