1
$\begingroup$

I just started with the BGE and am making a 2D mario-type scroller game. The level is long enough to require two cameras, so I made an invisible plane which on collision switches to the sexing camera. However, I also want to go back to the first camera. How do I switch back?

$\endgroup$
2
  • 2
    $\begingroup$ @ShadyPuck Regarding edits, just worth noting that edits should be substantial, see: meta.blender.stackexchange.com/a/242/241 $\endgroup$ May 27, 2016 at 15:43
  • $\begingroup$ I have seen it. Most edits that I do are substantial. @RayMairlot $\endgroup$
    – Shady Puck
    May 27, 2016 at 15:45

4 Answers 4

1
$\begingroup$

Stateless solution

I suggest to do the exact same thing.

So you get:

  • logic to switch from A to B
  • logic to switch from B to A

Ensure to avoid triggering both at the same time. e.g. have a according difference between the collision objects.

$\endgroup$
0
$\begingroup$

Go to the game logic editor and under actuator select scene then select set camera where it says restart. Then choose which which camera you want. Make sure to set the sensor for ever you need.

$\endgroup$
0
$\begingroup$

you could try to incorporate a property to go along with the plane. For example when your character hits the plane and the property is 0 set camera to camera1 then when character hits plane and property is 1 set camera to camera0

link to download blend click

$\endgroup$
3
  • $\begingroup$ I did that but if I add 2 planes side by side I'll get no where because as soon as I collide with the other it will bring me back to camera one. I apologise if I'm misunderstanding you. $\endgroup$
    – Ayush
    May 28, 2016 at 11:12
  • $\begingroup$ @Ayush look at the blend file in the link $\endgroup$ May 30, 2016 at 2:37
  • $\begingroup$ This is a state-full solution. Beside the event you measure what state you currently have. Usually you would check what camera is active. As this is not possible without Python you can use a proxy (the property). It is important to keep the property and the active camera in sync. This means when you switch to camera A, the property always switches to 1. When you switch to camera B the property always switches to 0. Ensure to disable [True Level Triggering] at the collision sensors. Otherwise the cameras will constantly toggle. $\endgroup$
    – Monster
    May 30, 2016 at 10:02
0
$\begingroup$

Python solution

Since this a general question about changing the camera in the BGE, I'd like to throw in a method using Python. The following screenshot shows an example where the camera is switched when the spacebar is pressed. It involves:

  • two cameras (cObserver and cFollow)
  • an object (LOGIC) carrying the script (nextCam)
  • a script containing the camera list and simple logic

enter image description here

Think of a racing game with several cockpit-, follow- or even spectatorviews with keyframed camerashakes.

I personally prefer this method when the number of cameras increases, since it's easier to maintain than logic bricks. Additionally you can run additional logic depending on the active view, like changing the zoom level of the active cam with KX_Camera.lens.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .