• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker [SOLVED]Can you clamp a physics object to current view?

J

Jaco

Guest
Hi

I have a PHYSICS object that I can move around with my analog stick on my controller.
I am very happy with the way it moves and interacts with walls etc.

It is however not the object my Viewport follows around, meaning it can go off the screen..
Is there a way to let the borders of my current view act the same as the walls in my game?
So basically just not allow the object to move outside of the screen.

Thanks
 
M

Matt Hawkins

Guest
If you put this in the step event of your physics object it will force it to stay inside the view -
Code:
phy_position_x = clamp(phy_position_x,view_xview[0],view_wview[0]);
 
J

Jaco

Guest
If you put this in the step event of your physics object it will force it to stay inside the view -
Code:
phy_position_x = clamp(phy_position_x,view_xview[0],view_wview[0]);
That only seems to work when the room starts, as soon as the view moves my object can't pass further than location of the borders the view had in its original position.
 
You tagged this post as GMS 2.

If that is the case, you should be using

// LEFT
camera_get_view_x()
// RIGHT
camera_get_view_x() + camera_get_view_width()
// TOP
camera_get_view_y()
// BOTTOM
camera_get_view_y() + camera_get_view_height()

to determine the borders of your view.
 
J

Jaco

Guest
You tagged this post as GMS 2.

If that is the case, you should be using

// LEFT
camera_get_view_x()
// RIGHT
camera_get_view_x() + camera_get_view_width()
// TOP
camera_get_view_y()
// BOTTOM
camera_get_view_y() + camera_get_view_height()

to determine the borders of your view.
Thank You so much kind sir, works 100%
 
Top