Moving camera along CollisionRay

In looking at methods for zooming the camera in and out on Ralph, it seemed like the easiest thing to do would be to cast a ray from the floater over Ralph’s head through the camera, then move the camera along this ray.

Is this possible? If so, what should I look at to learn about it?


If all you want to do is zoom in on ralph (probably not, but meh), search the forums for my post about zooming / binoculars / dolly zoom (zolly). You can change the FOV of the camera (Field Of View) to achieve a zoom in effect, as if you are looking down the scope of a gun.

Aside from aurilliance’s suggestion, if you actually want to move the camera, you can say camera.lookAt(floater) and then to zoom in something like camera.setPos(camera,0,dy,0). I typically will use either an interval or a camera update function to slowly move the camera to the desired position however.

skoster, If you do want to move the camera, rather than just zooming, don’t use a ray unless you need to. Panda’s vector math is easier than using one of them. You should be able to do something like the following…

# Say you want to move 20% from the camera's current location to ralph's,

percent = 20*1.0/100

v1 = ralph.getPos()
v2 =
deltavec = (v1 - v2)*percent

Hmm you might want to get the vectors relative to the camera instead tho. That can be done by saying spam.getPos(objecttoberelativefrom) I think…

Hmm, I probably should have been more clear as to specifically what I’m trying to achieve. I’d like to use the wheel_up and wheel_down functions to decrease or increase the perceived distance of the camera from the floater on the x, y and z axis. I would like to be able to do this while Ralph is moving.

When looking at your code, aurilliance, it seems like the easiest way to achieve the effect I want is to change the field of view of the camera like you suggest. This just requires a change in degrees of FOV, I can completely ignore the x, y and z coordinates since my change will not reference them. Thanks!

Mindstormss, I actually tried using something similar, but the problem is that I need to handle x, y, and z, which, combined with Ralph moving (thereby moving the camera, since I force the camera to stay behind Ralph for the most part) and these values changing, started to be overly complicated. Thats why I thought of a collision ray, I figured it would give me constantly updated information without my code having to compute it.

Concerning that vector math example, does getPos return x y and z in a list form or something? Because thats a pretty spiffy way of handling movement!

skoster, you’re welcome to the zoom code :wink: It was the first thing I ever posted here lol.

With regards with what you said to mindstormss, about having troubles with movements and x,y,z etc, that’s why I suggested getting the vectors relative to the camera, or ralph (that should nail your problems).

And yes, getPos() returns a tuple like Panda object, Vec3() from memory. It might be Point3() or so, but you get the idea - a little vector math can go a long way lol :wink:

by calling setPos(camera,0,±1,0) the camera will move in the direction it is pointing. calling lookAt will make the camera point at the desired location…I believe this is already done in the roaming ralph demo anyways. Why use vectors when you can make panda automatically figure out the spaces for you?

/facepalm!! Thats why my moving the camera code was going insane regardless of how I tried to set up the formula. I thought setPos set x, y, and z coordinates based on 0,0,0 being the bottom left corner of the map.

Apparently theres more than one way to skin a cat, but knowing which end of the knife is sharp helps. :blush: