x


GUITextures not lining up correctly

I'm making an Action RPG. Weird thing happening when my model's Transform is changing (meaning: while it's moving around). When my player gets within a certain radius of this model, a "panel" of sorts slides in from the left side of the screen showing its stats (it's name and health). While the model is stationary, everything looks fine, but when the model is moving, sometimes the different GUITextures that make up the panel don't line up correctly. Why? Because the Game Object that displays these GUITextures is rotated for some reason! Below is my functon:

void OnTriggerEnter(Collider e)
{
    if (e.gameObject.CompareTag("Player") && EnemyYPosition.getEnemyCount() < 4)
    {
        attacker = e.gameObject.GetComponent<Transform>();
        ep = (Transform)Instantiate(ePanel, Vector3.zero, transform.rotation);
        ep.Find("Name").guiText.text = gameObject.name;
        players.Add(e.gameObject);
    }
}

"ep" is the panel Prefab which has a GUITexture component. It also has two children: an object with just a GUIText (that displays the model's name), and another object with a GUITexture (which displays a gradient bar of variable length called the health bar). Since they're all group as one object, they should all move together, but when my model's movement script is activated, sometimes the different child object end up in different positions. Here are the relevant functions in the script attached to the panel object:

IEnumerator Start()
{
    gameObject.transform.position = lossPos;
    time1 = Time.time;
    time2 = 0.0f;
    StartCoroutine(Translation(transform, newPos, 1.0f, MoveType.Time));
    while (true)
    {
        g.pixelInset = new Rect(g.pixelInset.x, g.pixelInset.y,
            xHP * guiHP, g.pixelInset.height);
        //StartCoroutine(EnemyPanelPosition());
        yield return null;
    }
}

IEnumerator Translation (Transform thisTransform, Vector3 endPos, float value, MoveType moveType) 
{
    StartCoroutine(Translation(thisTransform, thisTransform.position,
         endPos, value, moveType));
    yield return null;
}

IEnumerator Translation (Transform thisTransform, Vector3 startPos, Vector3 endPos, float value, MoveType moveType) 
{
    float rate = (moveType == MoveType.Time)? 1.0f/value : 1.0f/Vector3.Distance(startPos, endPos) * value;
    float t = 0.0f;
    while (t < 1.0f) {
        t += Time.deltaTime * rate;
        thisTransform.position = Vector3.Lerp(startPos, endPos, t);
        yield return null;
    }
}

If anyone can help, that would be great.

more ▼

asked Jul 14, 2010 at 08:33 AM

cyangamer 1 gravatar image

cyangamer 1
40 18 12 19

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I've now fixed it by putting this command in the Start() method:

gameObject.transform.eulerAngles = Vector3.zero;

Now, the object will always face the same direction when instantiated!

more ▼

answered Jul 15, 2010 at 06:31 AM

cyangamer 1 gravatar image

cyangamer 1
40 18 12 19

In that case, you could try something else instead - change the last parameter of the instantiation to Quaternion.identity (And try to always use Quaternion.identity instead of eulerAngles = Vector3.zero )

Jul 15, 2010 at 08:50 AM Mike 3
(comments are locked)
10|3000 characters needed characters left

Add this after the while loop:

thisTransform.position = endPos;

You were only setting the position to the value of t before it hit 1

more ▼

answered Jul 14, 2010 at 09:30 AM

Mike 3 gravatar image

Mike 3
32.9k 19 80 290

Thanks. This may have inadvertently fixed something else, but it didn't fix my problem. After running some more tests, I have figured out what the problem is. I will alter my question shortly to reflect what the actual problem is, because I still don't know how to fix it.

Jul 15, 2010 at 06:21 AM cyangamer 1
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2802
x2028
x772
x465

asked: Jul 14, 2010 at 08:33 AM

Seen: 1356 times

Last Updated: Jul 15, 2010 at 06:29 AM