CREATE YOUR WORLD
Players & Characters: Advanced
Quarter View Example
5 min
zepeto character controls can be customized to use unity's new input system instead of v pad these are examples of setting the quarter view control step 1 camera view setting set the camera as quarter view (this is an example, so please modify the camera setting according to your project ) at this point, the camera's tag should be set to maincamara step 2 inputaction setting by defining a new inputaction for the qiarter view, you can control character movements through touch screen select create > input actions and set the file name as quarterviewactions move action type pass through move trigger action type button after creating hierarchy > create empty object, change the file name to quarterviewcontroller from quarterviewcontroller object, select add component and add the player input drag and connect the quarterview actions that you just created to the actions list change the behavoir to invoke unity events step 3 scripting write a script that calculates the direction of the character's movement through touch screen input select create > zepeto > typescript and rename it quarterview controller adds the script to the quarterview controller object import {zepetoscriptbehaviour} from 'zepeto script' import {playerinput,inputaction} from "unityengine inputsystem" import {callbackcontext} from "unityengine inputsystem inputaction" import {characterstate, zepetocharacter, zepetoplayers, zepetocamera} from 'zepeto character controller' import {camera, quaternion, time, vector2, vector3, waitforendofframe} from "unityengine"; export default class quarterviewcontroller extends zepetoscriptbehaviour { private mycharacter zepetocharacter; private startpos vector2 = vector2 zero; private curpos vector2 = vector2 zero; private playerinput playerinput; private touchpositionaction inputaction; private touchtriggeraction inputaction; private istriggered boolean = false; private istouchdown boolean = false; private canmove() boolean { return this istouchdown && !this istriggered; } onenable(){ this playerinput = this gameobject getcomponent\<playerinput>(); } start() { this touchtriggeraction = this playerinput actions findaction("movetrigger"); this touchpositionaction = this playerinput actions findaction("move"); this touchtriggeraction add started((context)=>{ this istriggered = true; this istouchdown = true; }); this touchtriggeraction add canceled((context)=>{ this istriggered = false; this istouchdown = false; }); this touchpositionaction add performed((context)=>{ if(this istouchdown) { this curpos = context readvalueasobject() as vector2; if(this istriggered) { this istriggered = false; this startpos = this curpos; } } }); zepetoplayers instance onaddedlocalplayer addlistener(() => { zepetoplayers instance localplayer zepetocamera gameobject setactive(false); this mycharacter = zepetoplayers instance localplayer zepetoplayer character; this startcoroutine(this inputcontrolloop()); }); } private inputcontrolloop(){ while(true) { yield new waitforendofframe(); if (this mycharacter && this canmove()) { var camrot = quaternion euler(0, camera main transform rotation eulerangles y, 0); var movedir = vector2 op subtraction(this curpos, this startpos); movedir = vector2 op division(movedir, 100); if (movedir magnitude > 0) { if(movedir magnitude > 1) movedir normalize(); var optmovedir = new vector3(movedir x, 0, movedir y); optmovedir = vector3 op multiply(optmovedir, time deltatime 80 ); this mycharacter move(camrot optmovedir); } } } } }