The Daily Click ::. Forums ::. Klik Coding Help ::. Need some help about the max function (it's about a radius)
 

Post Reply  Post Oekaki 
 

Posted By Message

Riptide



Registered
  26/07/2013 21:07:20
Points
  101
22nd September, 2013 at 22/09/2013 18:33:06 -

Hi there
I made a scrolling with 3 objects.
- The player
- The camera (The blue thing on the screens below)
- The target (The coordinates of the mouse actually)

The camera position is relative to the target and the player position.
Image

BUT, there's a problem. if i go with my mouse at the right of my screen, the camera will be able to go trough all the frame (yea, sorry for my (bad) english))
So i wanted to do a max radius for the camera (in pixels)
Image

I searched for the "Max" function and i don't understand how to use it, if you want the fomula for the camera placement i can give it

Thanks for your help guys, see ya

 
Working on some engines, working for the fun !

Fifth

Quadruped

Registered
  07/05/2003
Points
  5815

VIP MemberGOTW JULY 2010 WINNER!Kliktober Special Award TagGOTW HALLOWEEN 2011 WINNERPicture Me This Round 51 Winner!
22nd September, 2013 at 22/09/2013 19:16:02 -

It's a bit confusing, but "max" will give you the larger of two values, not the maximum. To get an upper limit like that, you would have to use "min".

It's something like this...

max ( 4 , 6 )

would result in 6, the greater value, and

min ( 4 , 6 )

would give you 4, the lesser.
So you'd want something like

min ( mouse_distance , max_distance )

 
Go Moon!

Riptide



Registered
  26/07/2013 21:07:20
Points
  101
22nd September, 2013 at 22/09/2013 20:32:25 -

Hi there, it (partially) works but i have a problem (two actually):

Image
The Upper-Left side is not affected

but the lower-right side is affected:
Image

And my second problem is that the range is a square, i think i can do a circle with Pi i guess, but i don't see HOW.

Anyway, thanks for helping !




EDIT here's my formulas for the camera's position

X AXIS:
Min(X("Player")+(Dist_X_Player-target*0.5), X( "Player" )+MaxRadius)

Y AXIS:
Min(Y("Player")+(Dist_Y_Player-target*0.5), Y( "Player" )+MaxRadius)

Where: "Dist_X_Player-target" & "Dist_Y_Player-target" = The distance between the player and the target (On the X/Y axis) and maxradius is the max radius (50 pixels here)

Edited by Riptide

 
Working on some engines, working for the fun !

Fifth

Quadruped

Registered
  07/05/2003
Points
  5815

VIP MemberGOTW JULY 2010 WINNER!Kliktober Special Award TagGOTW HALLOWEEN 2011 WINNERPicture Me This Round 51 Winner!
22nd September, 2013 at 22/09/2013 21:28:44 -

If you want to restrict the value within a range, you can use both max and min. Something like

max ( min ( x , 50 ) , -50 )

Would keep the value x restricted within the range of -50 to 50. For your coordinates, you could do

X AXIS:
Max(Min(X("Player")+(Dist_X_Player-target*0.5), X( "Player" )+MaxRadius), X( "Player" )-MaxRadius)

Y AXIS:
Max(Min(Y("Player")+(Dist_Y_Player-target*0.5), Y( "Player" )+MaxRadius), Y( "Player" )-MaxRadius)


...but this would still result in a rectangular boundary, as you're processing the restriction at the X/Y coordinate level. If, instead, you took the distance and direction from the player to the mouse, used min to restrict the distance, then used that to determine the X and Y coordinates, you could end up with a circular camera zone.

I see you're already finding the angle and distance (though it confuses me as to how you're ending up with a negative distance in the third image?), so it shouldn't be too much trouble to do.

 
Go Moon!

Riptide



Registered
  26/07/2013 21:07:20
Points
  101
22nd September, 2013 at 22/09/2013 21:44:24 -

Hey fifth, thanks for your reply, this works like a charm (i'll try a method for a circular radius, event if it looks complicated to do. like a circle radius right ?)
The reason i have negative values is for the camera placement. If i did set the value as an absolute value, it would not work in this case, because the camera would always be at the bot-right, it couldn't go to the right and go to the top (because the XPos of the camera would be lower the the XPos of the player (and same for the Y axis). I know my english isn't too good but i think you got it !



Edited by Riptide

 
Working on some engines, working for the fun !
   

Post Reply



 



Advertisement

Worth A Click