- Home /
Question by
khalilbenkassem2 · Feb 04 at 02:39 PM ·
camera-movementcamera movement
Character and Camera motion smooth in Editor, but jitters in Build,Character and Camera motion are smooth in Editor, but jittery after build
I have been struggling to get smooth character and camera motion in builds (in editor everything is smooth as butter). Once you start playing the game in a build, the character appears very jittery and the camera acts like it is getting hung up
here's my camera controller script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CamerController : MonoBehaviour
{
public Transform target;
private Vector3 offset;
private float idleYPos;
public LayerMask layerm;
public static CamerController instance;
// Start is called before the first frame update
void Start()
{
offset=target.position-transform.position;
idleYPos=this.transform.position.y;
}
private void Awake()
{
if (!instance)
instance = this;
}
// Update is called once per frame
void Update()
{
this.transform.LookAt(target);
Vector3 newPos=target.position-offset;
newPos.y=idleYPos;
transform.position=newPos;
if(Input.GetMouseButtonDown(0)){
checkForButtonkillButton();
}
}
private void checkForButtonkillButton(){
Ray ray;
RaycastHit hit;
ray=Camera.main.ScreenPointToRay(Input.mousePosition);
///Vector3 end=Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y,100f));
Debug.DrawRay(ray.origin,ray.direction*30);
if(Physics.Raycast(ray,out hit,1000,layerm)){
if(hit.collider.CompareTag("ButtonKill")){
hit.collider.gameObject.GetComponent<KillCanvasManager>().Attack();
print("Button kill klicked");
}
}
}
public void changeTarget(Transform newTragetTransform) {
this.target = newTragetTransform;
}
}
,here's my camero controller script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CamerController : MonoBehaviour
{
public Transform target;
private Vector3 offset;
private float idleYPos;
public LayerMask layerm;
public static CamerController instance;
// Start is called before the first frame update
void Start()
{
offset=target.position-transform.position;
idleYPos=this.transform.position.y;
}
private void Awake()
{
if (!instance)
instance = this;
}
// Update is called once per frame
void Update()
{
this.transform.LookAt(target);
Vector3 newPos=target.position-offset;
newPos.y=idleYPos;
transform.position=newPos;
if(Input.GetMouseButtonDown(0)){
checkForButtonkillButton();
}
}
private void checkForButtonkillButton(){
Ray ray;
RaycastHit hit;
ray=Camera.main.ScreenPointToRay(Input.mousePosition);
///Vector3 end=Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y,100f));
Debug.DrawRay(ray.origin,ray.direction*30);
if(Physics.Raycast(ray,out hit,1000,layerm)){
if(hit.collider.CompareTag("ButtonKill")){
hit.collider.gameObject.GetComponent<KillCanvasManager>().Attack();
print("Button kill klicked");
}
}
}
public void changeTarget(Transform newTragetTransform) {
this.target = newTragetTransform;
}
}
Comment
Your answer

Follow this Question
Related Questions
My camera is not linking with my movement 0 Answers
How to rotate and move the camera with correct orientation,How to move camera after it gets rotated 1 Answer
Automatic Camera Rotation in the 3D Game Kit 0 Answers
How to keep Auto Cam above an object 0 Answers
How can I make the camera have left and right movement without a player. 1 Answer