Hello everyone.
For my game, I’m trying to animate a simple cursor. The cursor consists on two parts:
The first part it’s a static square-like object which highlights a tile in my grid
The second part it’s a glove-like object, going up and down somewhere above the first object.
I’ve set up a simple prefab to do so, I’ve done it like this:
-
I’ve got two sepparate meshes, one for the square, called “square” and the other for the glove, called “glove”, they’re parented to the same gameObject, called “Cursor”.
-
Next, i set up a simple script, here it goes: EDIT: (Note that this script is attached to the glove, not to the parent, otherwise my question would make no sense at all)
public class CursorAnimation : MonoBehaviour {
public float Amplitude = 1.0f; public float frequency = 1.0f; public float yRotateSpeed = 1.0f; // Update is called once per frame void Update () { transform.position += new Vector3(0, Amplitude*Mathf.Sin(frequency*Time.time),0); transform.Rotate(new Vector3(0,0,yRotateSpeed)); }
}
However, this isn’t working, because while being static, the cursor behaves as it should, but when moving the glove up and down, it somehow modifies the position for the “Cursor” parent object, which seems to adapt to the average position between the square and the glove rather than being static, making movement impossible.
I don’t know what I’m doing wrong, I thought modifying the glove’s position would only affect it’s relative position to the parent but it’s actually affecting the parent as well, I can’t really see what’s going on, some help would be much appreciated.
Thank you very much.