How to extend/add length to Vector3
Asked Answered
B

1

0

Hi,

I have two Vector3 positions, one is the position of the player, the other is the position of the mouse in the 3D world. I am spawning a bullet at the player position and then Lerp-ing it to the mouse position which works fine.

I want to make the bullet go beyond the mouse position, somehow add length to the vector.

This is how I'm moving the bullet now:
this.Position = this.Position.Lerp(this.bullet_directon, 0.09f);

Botanize answered 9/12, 2023 at 12:33 Comment(0)
K
1

Botanize If you have a line segment going from endpoint A to endpoint B, to extend the endpoint B along its direction for some distance d to a new endpoint B1:

  • calculate the normalized direction vector AB by subtracting B from A and normalizing it.
  • multiply this direction vector by the distance d and add it to B.
Kibitzer answered 9/12, 2023 at 13:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.