Search Unity

Resolved Faster Translation?

Discussion in 'Entity Component System' started by veliefendi, Sep 16, 2022.

  1. veliefendi

    veliefendi

    Joined:
    Jan 14, 2017
    Posts:
    24
    I'm trying to go right and left, but when I write something like the code below, I don't go faster, but I go further. Of course I expected it to be like this, but how can I make it go the same distance faster?

    Code (CSharp):
    1. translation.Value.x += translationAmount * DeltaTime * speedAmount * direction;
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    speed = distance / time

    So if you don't want to change distance, then you need to decrease the duration you move the entity for. That does not mean trying to modify DeltaTime or changing speedAmount. That means decreasing the number of frames this function applies for, which is the timeDuration.

    Effectively:
    timeDuration = desiredDistance / desiredSpeed
     
    veliefendi likes this.
  3. veliefendi

    veliefendi

    Joined:
    Jan 14, 2017
    Posts:
    24
    I expected a method like
    transform.translate
    or
    math.mul
    , but that makes sense. Thank you.