title: LibGDX: how do I multiply vector with scalar without modifing original vector? (simple gravity system in Java game)
body: <p>I am currently implementing a simple gravity system in my game using LibGDX. However, I found that the way you multiply vectors with vectors and vectors with scalars is a bit different.</p>
  
  <p>In Unity, I would implement gravity like this:</p>
  
  <pre><code>    public Vector3 velocity;
      public Vector3 acceleration;
  
      private void FixedUpdate()
      {
          transform.position += velocity*Time.fixedDeltaTime;
  
          Vector3 force = Physics.gravity*GetComponent&lt;Rigidbody&gt;().mass;
          acceleration = force/GetComponent&lt;Rigidbody&gt;().mass;
  
          velocity = velocity + acceleration*Time.fixedDeltaTime;
      }
  }
  </code></pre>
  
  <p>Vector multiplication is very straight forward.</p>
  
  <p>In LibGDX, I am trying the following:</p>
  
  <pre><code>    import com.badlogic.gdx.math.Vector2;
  
      final protected Vector2 _gravity = new Vector2(0f, -9.82f);
      final protected float _mass = 1f;
      protected Vector2 _velocity;
      protected Vector2 _acceleration;
  
      public void Update(float deltaTime)
      {
          // Transform is a class containing a Vector2 called Position
          Transform.Position.add(_velocity.scl(deltaTime));
  
          Vector2 force = _gravity.scl(_mass);
          _acceleration = force.scl(1f/_mass);    
          _velocity = _velocity.add(_acceleration.scl(deltaTime));
  
          System.out.println(_velocity);
          // _velocity gets smaller and smaller and finally hits 0.
      }
  </code></pre>
  
  <p>This does not work, since the <em>scl()</em> method of Vector2 directly changes the vector itself, as can be seen in the Vector2 class of LibGDX:</p>
  
  <pre><code>public Vector2 scl (float scalar) {
          x *= scalar;
          y *= scalar;
          return this;
      }
  </code></pre>
  
  <p>I assume I want it to return a <em>new</em> Vector2, instead of changing the vector itself directly.</p>
  
  <p>How can I do that? Or am I completely wrong? Is there an easier way in LibGDX to multiply vectors with scalars using the "*" operator?</p>