- Home /
Jitter when using transform.position
So in my first person game I'm adding the hands/gun/equipment as a separate object.
This solved one of my other issues with having a smooth rotate but ANYWAY
So I got all that working but when I go ingame and move around well... the video can show you what happens
https://youtu.be/rdyAfX9AMxE
So I was wondering if there is an alternative to:
transform.position = target.transform.position (which I use to set it to the camera position)
Or perhaps a way I can get the smooth rotation working with a child object (cause y'know, it matches the parent so it was just awkward)
|
TLDR: To reiterate, my gun object is not a child of my camera (for reasons) and I'm using transform.position to move it to the camera every frame but this ends up looking jittery, plz help
The code I use to smoothly rotate my hand/gun which I believe is where my issue lies
public class HandRotator : $$anonymous$$onoBehaviour
{
private Vector3 v3Offset;
public GameObject goFollow;
[Range(0, 100)]
public float speed = 1f;
void Start()
{
transform.position = goFollow.transform.position;
v3Offset = transform.position - goFollow.transform.position;
}
void Update()
{
transform.position = goFollow.transform.position + v3Offset;
transform.rotation = Quaternion.Slerp(transform.rotation, goFollow.transform.rotation, speed * Time.deltaTime);
}
}
Answer by Systemfre1 · Jan 17, 2021 at 02:26 PM
Solved, for anyone having this issue in the future
I simply changed my script from Update do LateUpdate.
This way the object you are tracking moves first in Update, and this object will then match it's position later in the same frame in LateUpdate().
Your answer
Follow this Question
Related Questions
Transform player from one position to another after completing a goal 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Subtracting the position of transform from the position of Game Objects in a list. 1 Answer
How do I update the position of different prefabs to the current position? 0 Answers