#I have a 3rd person camera and I would like to block the camera in the room so that it cannot

1 messages · Page 1 of 1 (latest)

regal spear
#

Hello, I use cinemachine

simple kayak
#

The title got cut off, what was the full question?

regal spear
simple kayak
#

Im not sure if this solution is compatible with cinemachine, ive never used it before, but here is what i did to solve that issue:
From the point the camera orbits, do a spherecast towards the target camera position. If the ray hits a position either place the camera in that spot instead or move it slightly closer from there to make extra sure it doesnt clip

regal spear
simple kayak
#

Oh you arent using any scripts for the camera, Like i said i dont know much about cinemachine. It might have a build-in method for doing something like this

regal spear
#

Did you put a script on camera directly?

simple kayak
#

This is probably what you are looking for

regal spear
#

I see but unfortunately I can't find the problem

#

YEAAAAAAAAAAAH

regal spear
#
using UnityEngine;
using UnityEngine.InputSystem;

[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(Animator))]
public class PlayerBehavior : MonoBehaviour
{
    [Header("Movement Settings")]
    [SerializeField] private float moveSpeed = 3f;
    [SerializeField] private float rotationSpeed = 6f;

    [Header("Optional Particles")]
    [SerializeField] private ParticleSystem walkingParticles;

    private Rigidbody rb;
    private Animator animator;
    private Vector3 moveInput;

    private void Awake()
    {
        rb = GetComponent<Rigidbody>();
        rb.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
        animator = GetComponent<Animator>();
    }

    private void FixedUpdate()
    {

        Vector3 direction = new Vector3(moveInput.x, 0f, moveInput.z);
        if (direction.magnitude > 1f)
            direction.Normalize();

        Vector3 targetPosition = rb.position + direction * moveSpeed * Time.fixedDeltaTime;
        targetPosition.y = rb.position.y;
        rb.MovePosition(targetPosition);

        if (direction.sqrMagnitude > 0.01f)
        {
            Quaternion targetRotation = Quaternion.LookRotation(direction);
            rb.MoveRotation(Quaternion.Slerp(rb.rotation, targetRotation, rotationSpeed * Time.fixedDeltaTime));
        }

        float speed = new Vector2(direction.x, direction.z).magnitude;
        animator.SetFloat("Speed", speed);

        // Particules de marche
        if (walkingParticles != null)
        {
            if (speed > 0.1f && !walkingParticles.isPlaying)
                walkingParticles.Play();
            else if (speed <= 0.1f && walkingParticles.isPlaying)
                walkingParticles.Stop();
        }
    }

    public void Move(InputAction.CallbackContext context)
    {
        Vector3 v = context.ReadValue<Vector3>();
        // Inversion de l’axe Z pour Z = haut / S = bas
        moveInput = new Vector3(v.x, 0f, -v.y);
    }
}