Hello, how can I make this kind of movement?
I want my camera to rotate and move along a vehicle.
My script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraScript : MonoBehaviour
{
public Transform target;
public float smoothSpeed = 0.125f;
public Vector3 offSet;
public float rotateSpeed;
private float speedMod = 10.0f;
private Vector3 point;//the coord to the point where the camera looks at
private void FixedUpdate()
{
if (Input.GetMouseButton(1) == true)
{
point = target.transform.position;
transform.LookAt(point);
transform.RotateAround(point, new Vector3(0.0f, 1.0f, 0.0f), 10 * Time.deltaTime * speedMod);
}
else
{
Vector3 desiredPosition = target.position + offSet;
Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
transform.position = smoothedPosition;
transform.LookAt(target);
}
}
}
Your script is very naive compared to the desired camera movement. I would suggest doing something like this instead:
Create an invisible object to serve as camera target. Place it on the ship. Your dragging code should move the target, and your rotating code should rotate the target. This can be very naive, don’t put any damping or smoothing.
Then create a separate CinemachineVirtualCamera object and assign the invisible object as LookAt and Follow targets. Put Transposer in Body (LockToTargetWithWorldUp binding mode), and Composer in Aim. Adjust the damping to give smooth results when the invisible target is moved and rotated.
Yes, that’s great but after setting Transposer and Composer the camera cannot be moved. Instead, if I will set Orbital Transposer instead Transposer on Body, the camera is moving around the object but isn’t rotating to face the target.
What to do?
PS: The target is already set to Follow and LookAt