Changing the speed of transform.translate?
I have the player automatically moving in a certain direction, and it is going too fast, so was just wondering how I can reduce this speed? Thanks
transform.Translate(0.10F, -0.055F, 0 * Time.deltaTime);
I've tried changing Time.deltaTime to different integers but that didn't change the speed
Answer by bubzy · Oct 01, 2015 at 07:57 PM
0* anything is still 0 :)
change 0 to a variable called speed
or something and delcare that as public in declarations like
//in declarations
float speed = 0.1f; //change this value to change speed
//in your function
transform.Translate(0.1f,-0.05f,speed*Time.deltaTime);
Hmm seems the player sprite just disappears off the screen when I do that
so change the speed :) like 0.001f or 0.000000001f :D
I think the z value is changing as character appears to go off the map (it's 2d)
well, yes. you are using transform.Translate
the method for this is
public void Translate(float x, float y, float z, Transform relativeTo);
so you are entering the value on the Z axis as the position to increment, if you want this on a different axis, just put it in the other spot like
transform.Translate(0.1f,speed*Time.deltaTime,0); // for y axis
and so on, definitely worth using the scripting manual at http://docs.unity3d.com/ScriptReference/
But then the sprite player will be moving in the wrong direction, if I replace the -0.05 with the speed * Time.deltaTime (the player is moving diagonally)
it would be beneficial for you to start at the beginning and follow some tutorials.
Answer by goffyram · Aug 11, 2017 at 07:50 PM
Using Time.deltaTime should get the Translate to change your speed. Try this:
Translate(1f Time.deltaTime, -.5f Time.deltaTime, speed * Time.deltaTime);
Answer by JackhammerGaming · Jul 30, 2019 at 10:59 AM
public float trio;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetKey ("w")) {
transform.Translate (0 , 0 , trio*Time.deltaTime);