Movement within an object

M

Marko Kajtazi

Guest
Hey everyone,
I have been struggling with a game mechanic, so far I have when I click "E" a mini monitor (a object) pops up next to the player. I want so that the monitor has a mouse inside it, it should move with the arrow keys.
Can you help me?
thanks.
 
You'd want to find out how big the "screen" is of the monitor, and then figure out where its left / right / top / bottom sides are. Then treat those as values that your "mouse" can't move beyond.

So: if the mini monitor has a central point of origin, and the "screen" is 20 pixels either side, then the "mouse" can't move beyond 'monitor.x - 20' or 'monitor.x + 20' etc. The code for that would be pretty straightforward - using keycheck etc like you would for moving an instance, and then set these boundaries. Just think of it as a different type of collision.

If the left key is pressed say it moves the "mouse" 2 pixels left, so you'd check to see if its current position minus 2 pixels is less than 'monitor.x - 20' - if it is, then the mouse can only move as far as 'monitor.x - 20'. If it's larger than this "boundary" then it moves 2 pixels left.

Repeat for every other side, and you have contained it within the appropriate space.
 
M

Marko Kajtazi

Guest
You'd want to find out how big the "screen" is of the monitor, and then figure out where its left / right / top / bottom sides are. Then treat those as values that your "mouse" can't move beyond.

So: if the mini monitor has a central point of origin, and the "screen" is 20 pixels either side, then the "mouse" can't move beyond 'monitor.x - 20' or 'monitor.x + 20' etc. The code for that would be pretty straightforward - using keycheck etc like you would for moving an instance, and then set these boundaries. Just think of it as a different type of collision.

If the left key is pressed say it moves the "mouse" 2 pixels left, so you'd check to see if its current position minus 2 pixels is less than 'monitor.x - 20' - if it is, then the mouse can only move as far as 'monitor.x - 20'. If it's larger than this "boundary" then it moves 2 pixels left.

Repeat for every other side, and you have contained it within the appropriate space.
Thanks for helping me,
I did it and it worked perfectly.
 
Top