# Problem with the cam.

I cant to fix my cam to watch behind the palyer.

You’ll need to give more information, otherwise we have no idea what you’re trying to do, what you’ve tried so far, and where you’re stuck.

I want to make the view from the sky(like diablo) or behind the player(like freedom fighters) but alawys there is an erorr in the code like this:

``````import direct.directbase.DirectStart
from direct.actor import Actor
from pandac.PandaModules import *
import math

environ.reparentTo(render)
environ.setScale(0.25,0.25,0.25)
environ.setPos(-8,42,0)

player = ssw

# Correct the perspective before getting the distance
oldP = base.cam.getP()
base.cam.setP(0)

# Get the x and y distance beetwen the player and the camera
x = base.cam.getX(player)
y = base.cam.getY(player)

# The method for getting this angle is up to you
a = 60

# Linear transform to rotate around a point
w1 = x * cos(a) - y * sin(a)
w2 = x * sin(a) + y * cos(a)

# Set the new position
base.cam.setX(player, w1)
base.cam.setY(player, w2)

# Rotate the camera towards the player
base.cam.lookAt(player)

# Reset the pitch to its original value
base.cam.setP(oldP)

run()``````

and the error:

try math.cos ( and math.sin)

or from math import sin, cos

You really don’t want to use sin/cos for this, create a dummy node instead, reparent the camera to the dummy node, offset it and rotate the dummy node.

Oh realy I will not math cos and sin every frame.But with the dummy there is no efect.May be I have make error.Look:

``````import direct.directbase.DirectStart
from direct.actor import Actor
from pandac.PandaModules import *
import math
from math import sin
from math import cos

environ.reparentTo(render)
environ.setScale(0.25,0.25,0.25)
environ.setPos(-8,42,0)

#base.disableMouse()

player = ssw

dummy=render.attachNewNode("models/ssw.egg")
base.camera.reparentTo(dummy)
base.camera.setPos(4,42,0) # 10 = distance between cam and point
base.camera.setH(180) #this will rotate it 60 degrees around the point

run()``````

This is wrong:

``base.camera.setH(180) #this will rotate it 60 degrees around the point``

``dummy.setH(180) #this will rotate it 60 degrees around the point``

Right.But now I cant to move the cam with the

``base.camera.setPos(200,82,100) # 10 = distance between cam and point ``

because there is no effect.I thing that it is wrong.

Like this:

``dummy.setPos(200,82,100) # 10 = distance between cam and point ``

Offfffff.I MAKE IT.Thaks for the help.Here the right code:

``````base.disableMouse()

player = mydummy

dummy=render.attachNewNode("location of mydummy.egg")
base.camera.reparentTo(dummy)
dummy.setPos(30,30,10) # 10 = distance between cam and point
dummy.setH(60) #this will rotate it 60 degrees around the point

base.cam.lookAt(mydummy)``````

That code alone would never do it, sorry. But if you achieve a Diablo-like camera, i.e. a cam, that is fixed relative to the player, moves with him and the environment moves around … please post the code, I am trying that too.

Right now I use the method that others use too:

``````taskMgr.add(self.camerafollow, "camerafollowTask", priority = 30)

``````distance=target.getPos(camera)