Keep camera from moving along the Z Axis?

The camera that follows the player around is ‘vertex parented’ to the model,
I want to keep the camera from following it when it jumps, but free to move along x and y.

Problem here is the constraints don’t seem to work on child objects, so what can I do?

Thanks!

Have a child , that the camera is moved to, and then moved down to z level each frame.

Can’t quite understand what you’re saying, could you rephrase perhaps? :o

every frame, a ray is cast down from a empty where the camera is to be, that is parented to the player,

you then use the hitPoint, and a offset, to be the target of where the camera moves,

but I would not use a flat ‘move here’ every frame,

I would use

in raycaster


import bge
cont=bge.logic.getCurrentController()
own=cont.owner
Ray=cont.sensors['Ray']

if 'Cam' not in own:
    own['Cam']=bge.logic.getCurrentScene().objects['Camera']
else:
     if Ray.hitObject:
         B=Ray.hitPosition
         B.z+=2 ##offset from ground
         own['Cam'].worldPosition = ((own['Cam'].worldPosition*15)+B)*.0625
     else:
         own['Cam'].worldPosition = ((own['Cam'].worldPosition*15)+own.worldPosition)*.0625   


Here you are sir :smiley:

Attachments

DemoForPickles.blend (407 KB)

Well, the camera is a lot smoother this way…
but it still goes up and down along with the player.

An example of what I’m trying to achieve by removing the Z Axis would be kinda like the original Super Mario game.
You jump - the camera stays still, but follows along the X when moving left and right.

I will definitely use that camera setup in the file, though. It’s a lot better (and less stiff) than what I had before!

this, the camera is staying on the ground. but the camera is aiming at the player, you can just remove the tracking stuff in the camera, and it should be good, here I will do it real quick.

Attachments

DemoForPicklesBprReturn.blend (418 KB)

That’s what I thought at first, but couldn’t quite tell…
I parented a Cube to the empty and (because it didn’t rotate) thought it wasn’t working. My bad!

One of the methods I use (which can also be considered quite messy) whenever I want to restrict the translation/rotation of an object is through the use of an armature. For a camera locked on the XY plane, I would add an armature bone with a Copy Location constraint (make sure it is a bone constraint) and uncheck the Z checkbox. Then I would add an always sensor, connected to a run armature actuator in the logic window. Than all you have to do position your camera and parent it to the bone. Then you’re all set!


Keep in mind this method is good if you don’t want to fiddle with a lot of python. Otherwise BluePrintRandom’s method is more efficient and less memory intensive so use his if you are familiar with some code. This method is more for beginners.

Posted the file in my last post

this also has the benefit of tracking if you fall to far, or jump to another platform

I don’t know… not seeing any differences :confused:

The camera is certainly not staying on the ground,
even in the file you posted.

Could it be the version I’m using?

Ah, so it turns out it WAS the version of Blender I was using. (2.71)

Tried it with 2.67, works now!

EDIT: Nevermind, that wasn’t it. It’s working now in .71 too?!

The camera stays moving along the ground, UNLESS you change where the ray is hitting,

so you can have series of platforms, in both the forground and under the camera, or ???

uploading a video

Also, do you need to constrain the player to the Y and Z axis?

I can do this with code pretty easily,

Not on the player, no.
Currently have a constraint on the Y axis. No need for the other 2

Alright, so I finally got the camera set up in my scene, (and finally understand everything you’ve been explaining to me this past half-hour) but because the map is far away from the camera, the ray has nothing to hit. Have to improvise!

This method makes the camera so much more interactive, everything about it is great. So many possibilities, like having that wireframe cube be on a slant… and so on

In any case, thank you so very much BPR!

Attachments

DemoForPicklesBprReturnSmoothitz.blend (467 KB)

[QUOTE=BluePrintRandom;2770613]

Gonna use this camera method a lot more often, it’s really great!
Spent a solid 10 minutes trying to make the platform under the camera behave properly, all is good now.

Also, the file posted in your last post is pretty neat.
Gotta love Blender!

I do not understand why you need a ray.

I do not imagine a logic brick solution right now. But a simple Python solution.

camera.py


import bge

def followXY():
    target = getObjectFromActuator()
    
    position = getOwner().worldPosition
    position.x = target.worldPosition.x
    position.y = target.worldPosition.y

def getObjectFromActuator():
    for actuator in bge.logic.getCurrentController().actuators:
        try:
            return actuator.object
        except:
            continue

def getOwner():
    return bge.logic.getCurrentController().owner


For easier configuration it reads the target object from an camera actuator (which will not be activated!)

I suggest you use an empty as target. Vertex parent the target to the player. Otherwise the camera will be placed at the player. I’m sure that is not what you want.

If you need I can post you a demo.

I have what I came here for, but it’s up to you.
Everything is already set up, but a less convoluted configuration would be helpful