One object rotates around another object?

Hi all,

I can’t figure out how to make one object rotate around another object depending on mouse position. For example:

I have an actor, and a camera a bit behind it. If the middle mouse button is up, moving the mouse doesn’t influence the position of the camera. As soon as it is down, moving the mouse changes the camera position and makes it fly around the actor horizontally (still looking at it; radius is fixed; moving the mouse right makes the camera fly clockwise, left - counterclockwise). After releasing the mouse button any mouse movements don’t affect camera position again.

Can someone help, please?

Create an empty node and parent that to your object. Parent your camera to the empty node. Write a function that rotates the empty node based on the mouse movement. I don’t have specific code with me right now but those are the general steps that you want to do.

Thank you.
I can translate mouse movements into rotation angle. But I don’t know how to find new coordinates of the flying object, having just this angle and radius. this is more mathematical problem, as far as I can see.

you mean absolute coordinates like getPos(render) ?

Yes, I need to find absolute coordinates in order to move to this position my camera flying around the actor.
I know the actor position, the original camera position, the length of the radius (i.e. the distance from the actor to the camera). I can translate the mouse movements into an angle. And, have all these data, I need to calculate the new position for my camera. But I can’t figure out how…

Ok, I solved this by using sin() and cos() functions.
Here is the example from the Roaming Ralph sample that I play with:

mouseX =
if, self.centerX, self.centerY):
	# Update two important angles
	self.angleToFloater += (mouseX - self.centerX)
	self.angleToCamera = self.angleToFloater + 180
# Calculate resulting floater position
if self.angleToFloater < 0:
	self.angleToFloater += 360
if self.angleToFloater >= 360:
	self.angleToFloater -= 360
self.angleToFloaterRad = math.radians(self.angleToFloater)
self.floaterPos[0] = math.sin(self.angleToFloaterRad) * self.floaterDist
self.floaterPos[1] = math.cos(self.angleToFloaterRad) * self.floaterDist
# Calculate resulting camera position
if self.angleToCamera < 0:
	self.angleToCamera += 360
if self.angleToCamera >= 360:
	self.angleToCamera -= 360
self.angleToCameraRad = math.radians(self.angleToCamera)
self.cameraPos[0] = math.sin(self.angleToCameraRad) * self.cameraDist
self.cameraPos[1] = math.cos(self.angleToCameraRad) * self.cameraDist

I will make another thread for other questions.

You will almost never need sin cos and tan operations in Panda. Almost always you can use relative positions. Like, you can use obj.getPos(render) to get absolute coordinates.

that should be totally easy-> call your mousewatcher in a task -> get the position

mouseposX amplitude cos (time>frequnece)
mouseposY amplitude sin (time>frequence)