These are examples of setting FPS/TPS control.
STEP 1 : Fixing Camera Position
To fix the camera in TPS, go to ZepetoPlayers > ZepetoCamera > Zoom and set the Min and Max value to same.
Set the Look Offset Y value to 0.1.
To fix the camera in FPS, go to ZepetoPlayers > ZepetoCamera > Zoom and set the Min and Max value to -1.
Set the Look Offset Y value to 0.1.
STEP 2 : Scripting
Add a script that applies the rotation of the camera to the rotation of the character.
Add a script to correct the rotation of the character by receiving the camera rotate input (OnDragEvent).
import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
import { ZepetoPlayers, ZepetoCharacter, ZepetoScreenTouchpad, ZepetoCamera } from 'ZEPETO.Character.Controller';
import { Vector3, Time, Quaternion} from 'UnityEngine';
import { ZepetoInputControl } from 'RootNamespace';
export default class TPSController extends ZepetoScriptBehaviour {
private zepetoScreenPad: ZepetoScreenTouchpad;
private myCharacter: ZepetoCharacter;
private myInputControl: ZepetoInputControl;
private myCamera: ZepetoCamera;
Awake() {
this.myInputControl = new ZepetoInputControl();
}
Start() {
this.myInputControl.Enable();
ZepetoPlayers.instance.OnAddedLocalPlayer.AddListener(() => {
this.myCamera = ZepetoPlayers.instance.LocalPlayer.zepetoCamera;
this.myCharacter = ZepetoPlayers.instance.LocalPlayer.zepetoPlayer.character;
this.zepetoScreenPad = ZepetoPlayers.instance.gameObject.GetComponentInChildren<ZepetoScreenTouchpad>();
this.zepetoScreenPad.OnDragEvent.AddListener(deltaVector => {
console.log(`[OnDragEvent] : ${deltaVector.ToString()}`);
// The rotation of the camera is corrected according to the rotation of the character.
ZepetoPlayers.instance.ZepetoCamera.transform.RotateAround(this.myCharacter.transform.position,
Vector3.up, deltaVector.x * Time.deltaTime * 80);
});
});
}
Update() {
if ((null == this.myCharacter) || (null == this.myCamera)) {
return;
}
const lookAxisRot = Quaternion.LookRotation(this.myCamera.cameraParent.forward);
const projRot = Vector3.ProjectOnPlane(lookAxisRot.eulerAngles, Vector3.right);
// Match the rotation of the character with the forward direction of the camera.
this.myCharacter.gameObject.transform.rotation = Quaternion.Euler(projRot);
}
}