- Home /
how to stop child object from twitching?
I'm building a character select screen that swipe. I have one main gameobject that read swiping of finger. Each character has a parent gameobject nested under this one gameobject that reads when the character is swiped out of a certain range. and I have another child gameobject that is the image of the character. So there are 3 tiers of gameobjects. When the second tier of gameobject is within 1 and -1 of world space it scales up character image and sets it to x= 0. when out of range next character is scale and x = 0. all my characters sit perfectly at zero with out any twitching, but one character does twitch. I have been trying to figure out what I did wrong. What doesn't make sense to me is all the other characters work great except this one. here is my code that handles the character scaling and setting to x = 0.
public class ScaleCharacter : MonoBehaviour
{
public Vector3 minScale;
public Vector3 maxScale;
public float lerpTime;
public GameObject name;
public GameObject lockedTextGO;
public GameObject juggDescription;
public GameObject demonDescription;
Transform character;
// Use this for initialization
void Start ()
{
//Grabs the image of character
foreach(Transform child in transform)
{
character = child;
}
}
// Update is called once per frame
void Update ()
{
if(transform.position.x < 0.999f && transform.position.x > -0.999f)
{
//set characters name active
name.SetActive (true);
//initializes the characters pos
Vector3 characterPos = character.position;
//Scales character up
character.localScale = Vector3.Lerp (maxScale, minScale, 0);
//Sets character to middle of the screen
characterPos = new Vector3(0f, -1.0f, -5f);
//Sets characters pos
character.position = characterPos;
}
else{
/*
* What to do when the character isn't in the middle of the screen
*/
name.SetActive (false);
character.localScale = Vector3.Lerp (minScale, maxScale, 0);
character.localPosition = Vector3.zero;
}
}
}
This script sits in the parent GameObject to the character image.
Answer by mustafakemal · May 03, 2015 at 02:52 PM
you should check to find what is different in twitching object from other child objects. I think you must have add rigidbody or some physical component so these affect your gameobject's motion. Also check gameobjects local position in parent gameobject. good luck
The only thing that I can tell, thats is different, is the twitching character has a child sprite animation attached to it.
does animation play fluently ? Some times assets can't load in time. Esspecially when you use instantiate funtion to create copy of prefab. I check your code and i suggest that you should check lerp function bheviour. maybe you use it wrong. you can check this out
third parametter of lerp function musn't be zero! and if you want to ittarate a value of variable you should use this variable in lerp function as second or first parameter
Your answer
Follow this Question
Related Questions
Moving parent to position of child 0 Answers
Parent transform not following child transform 0 Answers
Transform child object over time and then destroy it. 1 Answer
Problem with making child an object 2 Answers
Position of parent-Object 2 Answers