rising camera problem(solved)

I have replicated the code of roaming ralph and replaced the models with my own along with emulating acceleration and deceleration through this:


#variables are as follow:
#self.speed   current speed of the character
#self.max     the maximum limit self.speed can reach
#self.inc     what increases self.speed
#self.min     the minimum self.speed can reach
#self.dec     what decreases self.speed

        if (self.keyMap["forward"]!=0):
            if self.speed<self.max:
                if self.speed+self.inc>self.max:
                    self.speed=self.max
                else:
                    self.speed+=self.inc
            self.player.setY(self.player, -(elapsed*self.speed))
            
        if (self.keyMap["forward"]!=1):
            if self.speed>self.min:
                if self.speed-self.dec<self.min:
                    self.speed=self.min
                else:
                    self.speed-=self.dec
            self.player.setY(self.player, -(elapsed*self.speed))

although I have replicated the roaming ralph code, it has a problem when the camera goes to higher ground and is unable to come down

this is how the camera looks at the character on flat ground

this is houw the camera looks at the character when it has reached the peak of the higher slope

lastly this is how the camera looks at the character when it tries to get down from the peak, notice a tiny green speck, that is the character that you saw in the first 2 images!

I wish for the camera to look at the character as it would in the first 2 images in any given situation

I understand abit of how roaming ralph’s camera works but am not understanding what makes the camera behaves this way

please dont leave me in the dark, at least tell me if this has been asked before so i can search for it elsewhere in the forum

or better yet, provide the link to the previously discussed topic

You’ll need to play with a nodepath that you’ll reparent to your player and then reparent the cam to the nodepath.
In roamingRalph tut, look at “floater” variable which is used that way.

are you refering to these few lines in the lower half of roaming ralph?

        self.floater.setPos(self.ralph.getPos())
        self.floater.setZ(self.ralph.getZ() + 2.0)
        base.camera.lookAt(self.floater)

well the only thing i did is change the 2.0 value for something smaller to fit my needs, and i also changed the name ralph to my own name but i doubt thats the problem

or maybe this in the upper half of the code?

        self.floater = NodePath(PandaNode("floater"))
        self.floater.reparentTo(render)

again, what i am using is very much the exact same code as the original romaing ralph with minor changes

the floater follows above the model i get that, but my camera is looking at my character no problem, just that the camera’s collision ray or the camera it self does not seem to move down when it has moved up, making it stuck at a certain height, as seen in my 3rd screenshot

unless my hypothesis is false, then i really need to relook on my understanding of python and panda…

If I understand, you need to provide a max distance between your cam and player. So, you would need to write something similar to:

if base.camera.getZ() - self.myPlayer.getZ() > maxDistance:
   base.camera.setZ(base.camera.getZ() - 2*elapsed)

thank you very much, it works very fine now

what puzzles me is why it worked for ralph but not for me

the only things that were changed were the models, or is there more to it than it seems…

okay sry for the initial rejoice

not as fine as i thought, now the camera is at least able to come down, but it comes down a little too slowly.

at least it does not stay stuck at a fixed height, but it is slow at coming down and returning to the original way it looks at the player

I played around with the code you gave me

base.camera.setZ(base.camera.getZ() - 2*elapsed)

i understand that “-2*elapsed” is the one that makes the camera move down but its kinda slow, and when i speed it up it gives a gittery effect which is definitely undesirable

is there another way around it?

hey everyone i found a solution to the terrain problem, now it works like a charm, although i forsee some problems when i try to implement jumping

anyway this is the code i used to replace the way roaming ralph handles its camera:

        self.highestZ=-300
        for i in range(self.camGroundHandler.getNumEntries()):
            entry = self.camGroundHandler.getEntry(i)
            z = entry.getSurfacePoint(render).getZ()
            if z > self.highestZ and (entry.getIntoNode().getName() == "pPlane1"):
                base.camera.setZ(z+0.5)

it now always has a constant distance (in the Z axis) away from the terrain. it can be abit far away from the player when the terrain is too steep, but bearable for now

anyway this is how it looks like in panda right now

this is the character on flat ground with the camera looking at it

here is the character walking on the slope with the camera still looking at it