- Home /
Vector2 MoveToward on HUD Canvas slow
The Vector2. MoveForward function seems to be what I want. I already used it for an enemy instance that walks arround with a speed of 3 time.Deltatime. But now I have an text object on my HUD canvas that starts at my players gameobject.position and I want to move it towards an text object in upper middle of the canvas. The first thing that difference from the enemy situation is the speed that I needed to configure higher to about 10 time.DeltaTime instead of 3 .. for the same speed? It seems even slower when I upload it to my android device?? Even with 100 time.DeltaTime??? But eventually it comes to it's target position :) Does this have something to do with the canvas that can change it's scale??
First I aline the source Hud canvas text object to the position of the player character:
streakPointText.transform.position = Camera.main.WorldToScreenPoint(new Vector3(characterTrans.position.x, characterTrans.position.y, characterTrans.position.z));
When the text object is in position, I move it towards the other main text object on the canvas with the following code in the update ():
float step = speedStreakText * Time.deltaTime; streakPointText.transform.position = Vector2.MoveTowards (streakPointText.transform.position, timeTextTrans.position, step);
if you are not changing these variables from the outside everything should work. mm... why don't you feed characterTrans.position straight into that function ins$$anonymous$$d of the .x .y .z components? what is speedStreakText? where do you set it?
Answer by DutchGuerrilla · May 30, 2015 at 11:37 AM
The vector3 only accepts 3 arguments not just 1, so I have to feed it with these 3 seperate values. The speedStreakText gets it's value from another function in another script. The strange thing is that I use the same function moveTowards on my enemy and it's not on the canvas. By just filling in on the enemy a value of speed = 3 it moves acceptable. For the canvas I have to put a value of almost speed = 150 and it's still not on the same speed... I beginning to believe it has something to do with the canvas that scales to fit the screen and that has some influence on the speed which degrades it with some factor?
Answer by DutchGuerrilla · May 30, 2015 at 11:36 AM
To troubleshoot things I put a single object on my canvas and tried to move it to a other location on the canvas. But it's still slow moving. This is the code:
using UnityEngine; using System.Collections;
public class TestMoveTowards : MonoBehaviour {
Vector2 targetPos;
// Use this for initialization
void Start () {
targetPos = new Vector2 (0.0f, -25.0f);
}
// Update is called once per frame
void Update () {
float step = 3 * Time.deltaTime;
transform.position = Vector2.MoveTowards (transform.position, targetPos, step);
}
}
Your answer
Follow this Question
Related Questions
Jerky motion using moveTowards at high speed 0 Answers
Canvas moves faster the second time it goes somewhere in the scene 2 Answers
Move Object A towards Object B at a definite speed 1 Answer
Get texture/material from UI canvas 0 Answers
Text mesh not showing on a world space canvas attached to a enemy gameobject, 2D 0 Answers