playMaker

Author Topic: Clamping / Setting a max radius for Move Position 2D  (Read 946 times)

Jeremy11K

  • Playmaker Newbie
  • *
  • Posts: 14
Clamping / Setting a max radius for Move Position 2D
« on: November 15, 2021, 01:53:24 AM »
Hey all!

I've been using PM for a while now, but only on a very basic level. I wanted to try to prototype something and am trying to create this slingshot mechanic in Playmaker:



I've been banging my head against this problem for a week now and I'm no programmer, so I'd really appreciate some help.

My slingshot/golf game game prototype is currently: A rigid body projectile attached to a tether with a spring joint. On Mouse Down I'm using the Move Position 2D action to move the projectile to the mouse position and on release, it waits 0.1 seconds, then detaches from the tether. It works perfectly as intended.

My problem: How do I set a max radius so I can't pull the projectile all over the screen? (The youtube video covers this at timestamp 10:50)

I'm using Get Distance to get a float distance from the projectile to the tether, but not sure if that float can be used.

I've tried clamping the mouseX and mouseY floats - this creates a box around the tether and jitters the projectile all over the place when exceeding the area.

I've also tried to use a Vector2 Clamp Magnitude which works great - but unfortunately, it only seems to work from world 0,0,0 - which for this prototype doesn't fit as I need to shoot the projectile from different world positions (I'll eventually have multiple tethers).

I've attached shots of my scene and PM breakdown. Any help would be much appreciated!

Cheers,
JK