0

I'm trying to make it so if my player hits "E" then they jump precisely to a specific target. The current code results in player jumping towards the target but not really making it there.

I've tried adjusting forceMultiply and ForceMode and adding an offset but I just can't get a result that simply consistently launches the player's rigidbody rb towards the anchorPoint position.

The code I have is:

private void Update()
{
    if (Input.GetKeyDown(KeyCode.E))
    {
        tryGrabbing = true;
    }
}

private void FixedUpdate() { if (tryGrabbing) { rb.AddForce(anchorPoint.transform.position * forceMultiply, ForceMode.Impulse); } }

Thank you for any help!!

Vaillancourt
  • 16,325
  • 17
  • 55
  • 61
yunum
  • 69
  • 6
  • 5
  • 2
    You should also get in the habit of doing a quick back-of-napkin dimensional analysis on physics code, to ensure your units make sense. Multiplying an absolute position by a scaling constant will never turn that position into an impulse - so the AddForce code you've shown here has no hope of doing what you meant it to. To make an impulse, we'd need a displacement (a difference between two positions), a time window, and a mass, in order to get a value in Newton-seconds (kg m / s) that makes sense to use as an impulse. – DMGregory Jul 18 '21 at 14:54
  • 1
    Hi @DMGregory , do you have advice for making Player jump at the Target front-on, rather than on top of it? Here is an image of what I mean. https://i.imgur.com/z9CNk9y.png Is this a matter of changing what formula is employed? – yunum Jul 19 '21 at 09:58
  • 2
    Aim at a lower target point, or choose a lower time value (increased launch velocity) or less gravity. This will flatten the arc so you hit your apex at/after the target rather than before descending to the target. – DMGregory Jul 19 '21 at 11:18

0 Answers0