The DistanceToGround value is way too big and places the platform way further from however much the player is even going to reach. Print($"last hook Y position: ") įloat DistanceToGround = (hookAbilityParameters.MaxHookForce, MathHelper.DegreeToVector2(hookAbilityParameters.MinExitAngle), hookAbilityParameters.MinExitAngle, hookAbilityParameters.Gravity, )
Private float HookRangeToGround(TrackPart lastHook) Vector3 platformPosition = new Vector3( + hookRangeToGround, 0) ĪctivatePlatformSpawner(platformPosition) Vector3 lastHookGroundPosition = new Vector3(, 0) įloat hookRangeToGround = HookRangeToGround(lastHook) This is how I am trying to achieve that: private void HookSpawnerFinished(TrackPart lastHook) What I want is that after the last spawned hook, the platform will be placed exactly at where the player will reach at position.y = 0 What I am doing is I have an infinite level that spawns platforms and hooks. I have attempted to calculate it with the following formula, but it doesn't seem to give me the correct result: public static float Range(float velocity, Vector3 direction, float angle, float gravity, float heightFromGround)įloat xVelocity = velocity * direction.x įloat yVelocity = velocity * direction.y įloat result = (xVelocity * (yVelocity + Mathf.Sqrt(Mathf.Pow(yVelocity, 2) + 2 * Mathf.Abs(gravity) * heightFromGround) / Mathf.Abs(gravity))) What I am trying to do is having the player launched off from a point with known velocity, height from ground, angle and gravity.Īnd I am trying to find is what the distance the player will cross until he reaches the ground again.