Home Game Development lighting – Character Controller reveals in scene however not in sport. Unity 3D

lighting – Character Controller reveals in scene however not in sport. Unity 3D

0
lighting – Character Controller reveals in scene however not in sport. Unity 3D

[ad_1]

So at the moment I awoke and realized that after I press play my character controller turns black, the size on the z axis is 0 and all the youngsters will not be seen. Now the factor this solely occurs after I press play if I do not every part is ok in my scene and sport view.

Player (Parent object)
enter image description here

Player transfer script

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;

public class PlayerMove : MonoBehaviour
{
    public CharacterController controller;
    public float gravity = -30;
    public float sphereRadius = 0.2f;
    public Transform groundCheck;
    public LayerMask groundMask;
    public float jumpHeight = 3f;
    public float sprintSpeed = 20f;
    public float walkSpeed = 15f;
    public float crouchHeight = 0.5f;
    public float crouchSpeed;
    public float startHeight;

    personal Vector3 velocity;
    personal bool isGrounded = true;
    personal float velocity;

    personal void Start() {
        velocity.y = 0f;
        velocity = walkSpeed;
        crouchSpeed = velocity / 2;
        startHeight = rework.localScale.y;
    }

    // Update is named as soon as per body
    personal void Update()
    {
        isGrounded = Physics.CheckSphere(groundCheck.place, sphereRadius, groundMask);

        float x = Input.GetAxisRaw("Horizontal");
        float z = Input.GetAxisRaw("Vertical");

        Vector3 transfer = rework.proper * x + rework.ahead * z;
        controller.Move(transfer.normalized * velocity * Time.deltaTime);

        if (velocity.y < -0.35f)
        {
            velocity.y = -0.35f;
        }

        // Jumping and crouching
        if (Input.GetButtonDown("Jump") && isGrounded)
        {
            velocity.y = jumpHeight;
        } else if (Input.GetKey(KeyCode.LeftShift)) {
            velocity -= 7.5f;
            rework.localScale = new Vector3(rework.localScale.x, crouchHeight, rework.localRotation.z);
        } else if (!Input.GetKey(KeyCode.LeftShift)) {
            velocity = walkSpeed;
            rework.localScale = new Vector3(rework.localScale.x, startHeight, rework.localRotation.z);
        }

        // Sprinting
        if (Input.GetKey(KeyCode.LeftControl))
        {
            velocity = sprintSpeed;
        }
        else if (!Input.GetKey(KeyCode.LeftControl))
        {
            velocity = walkSpeed;
        }

        velocity.y += gravity * Time.deltaTime * Time.deltaTime;
        controller.Move(velocity);
    }
}

Player script

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;

public class Player : MonoBehaviour
{
    public float well being = 100f;

    public void TakeDamage(float quantity)
    {
        well being -= quantity;
        if (well being <= 0)
            Destroy(gameObject);
    }
}

Main Camera object
enter image description here

Camera look script

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;

public class CameraLook : MonoBehaviour
{
    public float sensitivity = 100f;
    public Transform playerBody;
    
    personal float xRotation;

    personal void Start() {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.seen = false;
    }

    // Update is named as soon as per body
    void Update()
    {
        float mouseX = Input.GetAxis("Mouse X") * sensitivity * Time.fixedDeltaTime;
        float mouseY = Input.GetAxis("Mouse Y") * sensitivity * Time.fixedDeltaTime;

        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);

        rework.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
        playerBody.Rotate(Vector3.up * mouseX);
    }
}

Hierarchy
enter image description here

Here is a comparability for when i’m enjoying vs when not

not enjoying
not playing

enjoying
enter image description here

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here