- Home /
Script wont work for me please give me answers or a new script,camera folllow script is very janky and twitchs alot please help
I either need some answers on why this wont work and keeps twitching every where please help. It might be to simple and maybe that's what it is but here is the script so you can see for yourselves
using UnityEngine;
public class FollowPlayer : MonoBehaviour
{
public Transform player;
public Vector3 offset;
void Update()
{
transform.position = player.position + offset;
}
}
,Right, so to start off i was trying to make a game, and due to my lack of experience as a unity newbie (or coding in general), I dont know what the problem is and dont know how to fix it here is the script. it is very simple and that might be the problem here
using UnityEngine;
public class FollowPlayer : MonoBehaviour
{
public Transform player;
public Vector3 offset;
void Update()
{
transform.position = player.position + offset;
}
}
The offset value is (0,0,0) Why are you adding that?
it's a public variable, i assume OP has set an offset value in the inspector
Answer by Long2904 · Jul 22, 2021 at 06:17 AM
Can you be more specific about the camera movement? What did you mean when you said it was janky and twitches a lot? Are you making a 2d or 3d game? Is your camera always have to be at the same position as the player plus offset? What do you want your camera to behave? Be more specific about your problem. At first glance, I don't see anything weird about your code. How does your player move in this game (e.g left-right in 2d)?
Answer by rage_co · Jul 22, 2021 at 06:33 AM
This can be a result of using rigidbodies since their update cycle runs on FixedUpdate which runs at fixed intervals rather than Update which as you know runs every frame, however just like @Long2904 said, you question is extremely vague. I would suggest parenting your player to the camera however, this may solve the problem. Hope this helps