I’m trying to implement a parabolic projectile which
- arrives at a target at the end of its parabolic curve (two intersections of axis of symmetry will be the startPos and destinationPos and the axis of symmetry is a straight line between startPos and destinationPos)
- does this within a time constraint (ex: arrives in 1 second)
Here is how I am initializing velocity:
inline void parabolicInitialVelocity(const glm::vec2& startPos, const glm::vec2& destinationPos, float totalTime, glm::vec2& velocity){
glm::vec2 displacement = {destinationPos.x - startPos.x, destinationPos.y - startPos.y};
const float gravityFactory = .5f; // increase to make parabola more dramatic
velocity.x = displacement.x / totalTime;
velocity.y = (displacement.y - gravityFactory * 9.8f * totalTime * totalTime) / totalTime;
}
And here is how I am updating these entities, each frame:
auto& position = entity.GetComponent<TransformComponent>().position;
auto& velocity = entity.GetComponent<RidigBodyComponent>().velocity;
const auto& pmc = entity.GetComponent<ParabolicMovementComponent>();
velocity.y += gravity * deltaTime;
position.x += velocity.x * deltaTime;
position.y += velocity.y * deltaTime;
I’m unsure about what to try to fix this. please let me know if you have any ideas. thanks.