playMaker

Author Topic: Clamp [SOLVED]  (Read 9089 times)

plumbjet

  • Playmaker Newbie
  • *
  • Posts: 3
Clamp [SOLVED]
« on: November 28, 2011, 03:02:20 PM »
Hi All

Please go easy on me as I am new to unity and playmaker and do not know any scripting, this is what i am trying to do.

I have a camera that can be moved with the left click of the mouse and drag left and right, this moves the camara along the X xais thats all ok ,what iam trying to do is Stop the came from being able to move past a position.
The Drag camera part was done with the camera 3d drag template posted by jeanfabre, i just can not work out how to clamp the camera position. I do hope someone will be ble to help me out
« Last Edit: November 30, 2011, 04:04:41 PM by alexchouls »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Clamp
« Reply #1 on: November 29, 2011, 04:44:57 AM »
Hi,

One quick way to do that would be to maintain two fsm variable one for the min position and one for the max position ( on the axis you want to work with).

Instead of injecting directly the absolute position, store the camera start position, use the "deltaDragResult"  of my mouse drag custom action, clamp it and then add the camera start position with the clamped result, and inject this into your camera position.

Does that make sense?

so:, let's say you want to clamp the z axis

one time:
-- store the start position in a fsm var ( "startPos" )

every frame when dragging
1: extract the z value of the deltaDragResult ( "deltaDragResult_Z" )
1: store the clamped value of the deltaDragResult_Z of the mouse drag custom action ( "ClampedDelta_Z" )
2: store the absolute position by adding together "startPos" and "ClampedDelta_Z" ("camPos")
3: set the camera position to "camPos"

If you are having trouble implement this, I'll make a working example.

 Bye,

 Jean

plumbjet

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Clamp
« Reply #2 on: November 29, 2011, 01:52:17 PM »
Hi Jeanfabre

Thank you for the reply to my problem, i under stand what i should be doing to get this to work but can not work out how to do it with the playmaker actions, I am hopeing it will get easyer the more i play around with it and see how thing are done, If i could take up a litttle more of your time and ask if you could make the working example for me. Thank you for helping me out in learning how all this works.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Clamp
« Reply #3 on: November 30, 2011, 02:17:24 AM »
Hi Plumbjet,

 Here we go, I took the prefab from the mouse drag example and modified it to clamp the camera movement on its x axis ( the vertical axis is completely disabled, seemed logical as i did it, and better show the behavior, but can be easily enabled back).

Please find the prefab attached to this post.

Explanation:

1: drag the prefab onto your scene. delete the main camera ( the one not inside the prefab).
2: select the main camera
3: select the "clamped position" fsm
4: select the "drag camera and clamp" state

ok: first thing, after I take the dragresult from the drag fsm, I simply set to 0 the axis I don't want, in our case the z axis of the drag,so that the camera only moves on the x axis.

Now, to clamp the camera movement, I created a variable "clamp distance". This is the absolute distance form both side starting at 0 int he world coordinate. So before setting the prefab position, I clamp the "new position" vector so that it's distance ( the vector distance property) is not bigger than the "clamp distance" value.

 And that's it, the rest of the prefab remains untouch.

 this is one way to do it, and has some restrictions, but this gives you an idea and a starting point. If you want to have the camera anywhere in the world, you will need to do more math and vector operations. Also if you want to clamp with different values on the left and right drag, you'll need to clamp each axis individually. sams if you want to clamp the vertical drag as well.

Hopefully, you'll get the idea behind the process, and will be able to extrapolate on this. If not, provide a description and I'll try to match your needs.

 Bye,

 Jean

« Last Edit: May 27, 2013, 01:25:40 AM by jeanfabre »

plumbjet

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Clamp
« Reply #4 on: November 30, 2011, 12:14:54 PM »
Hi Jenanfabre

Thank you so much  for the fast reply and the time spent doing this for me, you have done just what i needed. and also it has give more info to work with.

Thank you again Plumbjet

parallel

  • Full Member
  • ***
  • Posts: 155
Re: Clamp [SOLVED]
« Reply #5 on: May 26, 2013, 07:13:35 PM »
Hi, is there an updated version of this prefab or the 'drag' action which it relies on? (I get a 'missing action'-drag )

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Clamp [SOLVED]
« Reply #6 on: May 27, 2013, 01:24:57 AM »
Hi,

 ok, I have re attached the prefab on that post above and the action needed, I am not sure why I haven't added that action in the package, sorry. The action si available on the forum tho.

http://hutonggames.com/playmakerforum/index.php?topic=272.msg1087#msg1087

bye,

 Jean

parallel

  • Full Member
  • ***
  • Posts: 155
Re: Clamp [SOLVED]
« Reply #7 on: May 27, 2013, 04:25:30 AM »
Thanks Jean!