How do you restrict a camera and entity movement??

Blitz3D Forums/Blitz3D Programming/How do you restrict a camera and entity movement??

RubyEnemy(Posted 2016) [#1]
How do you stop the camera and entity from going out of the area that you want them to leave? Such as if the player moved off the screen he wouldn't be aloud to and couldn't pass the boundaries.


angros47(Posted 2016) [#2]
You can create a transparent cube, use a flipmesh command on it, and put the camera and the player inside it. Then, you set collisions between camera and cube... if camera tries to go outside the cube, it would be stopped


RemiD(Posted 2016) [#3]
You could create a collidable to restrict where the player (with an ellispoid collider) can go or you could allow movement only if the new position will be inside a zone (is in circle ? is in rectangle ? is in triangle ? is in a flat shape made of triangles ?)


Kryzon(Posted 2016) [#4]
To move an object you apply an offset to the position of the object (it's what MoveEntity does, for example).
You know the future position of the object before moving it: futurePosition = currentPosition + offset

Before applying that offset and actually moving the object, you are free to do any tests on the future position of the object in your code: "is that position going to be outside the boundary?"
Depending on the result of those tests you can choose to not move the object.

When the player is pressing a key to move the object and your code doesn't let the object move because of a condition, this is what gives the feeling of a physical barrier.