rotate with mouse?

how do i make a model, rotate with the mouse… ( like in roaming ralph tut when you press left, he rotates to the left, so when my mouse is to the left
the object faces to the left, and if you move it a little to the up, the object faces left-up )

Well, one way to do it would be to use the lookAt function. You pass it either a node or a Point3 and it will change the HPR of you model to look at that node or point.

For following a mouse I’d do this:

import direct.directbase.DirectStart
from direct.task import Task
from pandac.PandaModules import *


class LookAtDemo():
    def __init__(self):

        self.smiley = loader.loadModel("teapot")
        self.smiley.setPos(0, 20, 0)

        taskMgr.doMethodLater(0.03, self.trackMouse, "trackMouse")

    def trackMouse(self, task):
        if base.mouseWatcherNode.hasMouse():
            self.smiley.lookAt(Point3(x, 0, y) * MULTIPLIER)
        return task.again
lookAtDemo = LookAtDemo()

I’m using a multiplier so that I can change the sensitivity of the movement.

I’m sure there are other way’s but this should at least get u started.

you always stays with the problem that the mouse collides with the borders of the screen!! i figured this out:

class World(DirectObject):
	def __init__(self, main):
		#======Mouse Handlers======#
		self.mouseBoxSize = #Mousebox
		self.centerX = #Screen width center
		self.centerY = height center

		self.mouseXMin = self.centerX - self.mouseBoxSize #Lowest X limit
		self.mouseXMax = self.centerX + self.mouseBoxSize #Highest X limit
		self.mouseYMin = self.centerY - self.mouseBoxSize #Lowest Y limit
		self.mouseYMax = self.centerY + self.mouseBoxSize
#Lowest Y limit, self.centerX, self.centerY) #Move the mouse to the center

		self.mouseY = 0 #define the mouse variables
		self.mouseX = 0
		self.mouseXFac = 0
		self.mouseYFac = 0

		#======Tasks======# add the task
		task = taskMgr.add(self.MouseControl, "Task_Mouse")

	#======Task Function======#
	def MouseControl(self,task):
		mouse = #Get the real position
		mouseX,mouseY = mouse.getX(),mouse.getY() #Set temponary mouse vars

		# If the mouse passes the borders, replace it back and add or subtract the factor
		if mouseX < self.mouseXMin:, self.centerX, mouseY)
			self.mouseXFac -= 1
		if mouseX > self.mouseXMax:, self.centerX, mouseY)
			self.mouseXFac += 1
		if mouseY < self.mouseYMin:, mouseX, self.centerY)
			self.mouseYFac -= 1
		if mouseY > self.mouseYMax:, mouseX, self.centerY)
			self.mouseYFac += 1

		#Set the calculated mouse positions
		self.mouseX = mouseX - self.centerX + self.mouseBoxSize*self.mouseXFac
		self.mouseY = mouseY - self.centerY + self.mouseBoxSize*self.mouseYFac
		return Task.cont

every time the mouse position gets smaller or larger than the self.mouseBoxSize

it will be replaced to the center of the screen and the game remembers how much time the mouse passed the limit

self.mouseYFac and self.mouseXFac are the numbers of times the mouse passed the limit

self.mouseY and self.mouseX are the recalculated mousepositions

self.mouseY = 0 and self.mouseX = 0 is in het midden van het scherm!

to use this for a node camera this way: