- Home /
Can't get smooth 2d movement for an object using transform.position
So I have 3 objects doing a transform.position type of thing. One object follows the player, mirroring his every move. The camera follows the player, doing the exact thing. Then a rectangle follows the object following the player. The object following the object following the player, is horrible stuttery. And I don't now why.
Here is the script for it.
using UnityEngine;
using System.Collections;
public class Shield : MonoBehaviour
{
GameObject shieldBase;
Transform rotation;
Vector2 shieldPos;
void Awake()
{
shieldBase = GameObject.FindGameObjectWithTag ("Follow");
}
void Update()
{
ShieldMovement ();
}
void ShieldMovement()
{
rotation = shieldBase.transform;
shieldPos = shieldBase.transform.position;
this.transform.rotation = rotation.rotation;
this.transform.position = shieldPos;
}
}
Incredibly simple code. All it needs to do is change it's position, to the other objects' position every frame. Yet it can't seem to do that. The object it needs to follow, is moving perfectly fine. Yet this object can't seem to keep up for some reason.
It has a rigidbody2d with gravity and mass set as low as possible, i've tried using the interpolate, does nothing. I've tried setting to kinematic. I've removed the rigidbody entirely. Still constant stuttering. Even on the build & run version.
I've noticed this problem a lot in unity, objects just not being able to move without irritating stutter.
Answer by Caelorum · Apr 28, 2015 at 11:33 PM
Apparently it had something to do with script execution order. I'm assuming one script was moving too late for the other script to follow.
Your answer
Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
Modifying the Transform of a GameObject 1 Answer
How do I check where my character is moving before he moves there? 1 Answer
Why isn't my object position (transform.position) updating? 1 Answer
transform.position not setting position OR animation setting position even though it shouldn't 0 Answers