Search Unity

Pinball - Slingshot - How to

Discussion in 'Scripting' started by DurstXD, Aug 20, 2014.

  1. DurstXD

    DurstXD

    Joined:
    Mar 25, 2013
    Posts:
    7
    Hi guys,

    I'm working on a 3D Pinball Table and everything was working just fine (physics, table, bumpers, flippers, etc) until I got stuck at the slingshot.
    What I want to do is: as near as the ball hit on the middle of the slingshot, more force will be added to the ball (see image attached).
    slingshot.jpg
    I don't know how to start programming that, nor even where I'll put the code(s) (on the ball or on the slingshot itself ?). I've already tried some stuff, but in vain.
    Does anyone have any idea on how to do that? If yes, please, explain in a simple way (and if you'll give examples, please use C#).

    Well, that's it.

    Thanks.
     
    ronaldbura likes this.
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Depends on how your ball-object collisions are being handled
    When you detect a collision happens somewhere along the bouncy surface, you can then calculate how far along the line it happened (inverse lerp), then scale the added force depedant on that (more force at 0.5 - middle, less force towards 1 or 0 ends)
     
    ronaldbura likes this.
  3. IsGreen

    IsGreen

    Joined:
    Jan 17, 2014
    Posts:
    206
    Attach AnimationCurve to Collider, and evaluate bounce considering the impact position and Collider rotation(forward).