How to make a camera follow a sphere without rotating?

Game Engine, Players & Web Plug-in, Virtual Reality, support for other engines

Moderators: jesterKing, stiv

Segia
Posts: 2
Joined: Sat Apr 18, 2009 8:59 pm

How to make a camera follow a sphere without rotating?

Postby Segia » Sat Apr 18, 2009 9:04 pm

Hi all,

I'm making a game where you controll a ball, and roll it through a world. However, when I make my ball parent to the camera, the camera tumbles over whenever I roll. Is it possible to have the camera only rotate left an right when it follows the ball?

Thanks in advance,

Segia

gizmo_thunder
Posts: 1
Joined: Wed Mar 11, 2009 6:17 am

Re: How to make a camera follow a sphere without rotating?

Postby gizmo_thunder » Tue Apr 28, 2009 9:01 am

Segia wrote:Hi all,

I'm making a game where you controll a ball, and roll it through a world. However, when I make my ball parent to the camera, the camera tumbles over whenever I roll. Is it possible to have the camera only rotate left an right when it follows the ball?

Thanks in advance,

Segia

You will have to write a python script to just take the position of the object you want the camera to follow and set the position of the camera based on that. This is how i used to do it.

Noz
Posts: 23
Joined: Wed Apr 29, 2009 3:32 pm

Postby Noz » Wed Apr 29, 2009 3:41 pm

Parent an empty to the sphere then parent the camera to the empty.

Segia
Posts: 2
Joined: Sat Apr 18, 2009 8:59 pm

Postby Segia » Fri May 08, 2009 1:53 pm

Noz wrote:Parent an empty to the sphere then parent the camera to the empty.


Tried that, but the empty rotates when I parent it to the sphere, thus rotating the camera. :?

bmud
Posts: 169
Joined: Sun Feb 08, 2004 8:13 am
Location: Raleigh, NC, USA
Contact:

Postby bmud » Wed May 27, 2009 11:22 pm

If you're doing this for the purposes of making a FPS, then you should really just turn off rigid body ti disable rotations on the sphere.

But let's say you have special needs. Here's how you copy location. Obviously you'll have to change the names to match your needs

Code: Select all

import GameLogic
scene = GameLogic.getCurrentScene()
Camera = scene.getObjectList()["OBCamera"]
Sphere = scene.getObjectList()["OBSphere"]

Camera = Parent.getPosition()
Sphere = Sphere.getPosition()

#this algorithm smooths things out a tiny bit. Otherwise you get an unwanted jittering effect
xyz = [0.0, 0.0, 0.0]
xyz[0] = (Sphere[0] + Camera[0]*2)/3
xyz[1] = (Sphere[1] + Camera[1]*2)/3
xyz[2] = (Sphere[2] + Camera[2]*2)/3

Camera.setPosition(xyz)


To copy rotations, just change "Position" to "Rotation" or mix and match

N00B3R
Posts: 17
Joined: Mon Jul 27, 2009 5:07 am
Location: Canada

Postby N00B3R » Mon Jul 27, 2009 6:41 am

Thanks for the code post, I'll try and find out how to do that...

Well that being said I'm obviously a noob but I would like to see if this code will work with what I have planned...

With the same circumstance ie. object spinning... could I have the physics turn the model - Have the camera pivatable (will try out another thread, or if you could help out also) and fixated on the ball

I would just like to know if that code would still work, as I have no clue about python and am not sure how hard it is to find out how to use it...

I'll tell you what I've tried and what would happen...

First off I tried what the poster said and just parented it, but because I switched from using only force to using a spin animation with the force and it spun the camera. Then I started finding out which motion variable I should use, so I switched between force, torque, and angular velocity, so far the torque+force works best for what I want to accomplish but how it works normally is kinda whacked out ie. after you move forward its fine, then you move sideways its fine but then you move forward or backwards its axis is messed... In other words you try and go forward and it spins, or is off axis and rolls away...

So my solution to that was to try and make an empty the parent of the sphere and have the sphere follow the empty, that way I can have all forces needed for movement ie. 8 way movement (Ang. V. spins the ball but not diagonaly). Now also I want the camera to pivot on the sphere through keyboard comands (easy to do but the spinning camera is... wack...) Now I don't know enough about blender to know if you could attach armatures, or something else to do what I want... Basicaly I want to make a ball that can move around a world... Everything else I will just experiment with and take my time to tweak and w.e but this is major, and it is to hard to "wing it" as I don't know what needs to be scripted or not... If you know or have any codes on hand it will help, but otherwise I would just like to know what I can use blender for and what I need to learn python for (I have NO quams over learning some python so no worries)... Also If you could quickly tell me how each part of the code is needed for what (just so I can understand better without asking a crap load of questions)


Well It was a long one but I hope some people can help me out here, maybe even help others starting out.

Thanks BIG in advance
N00B3R
LATEST ::WIP::

Geometry Planet: Platform, Puzzle game with RPG style upgrades and more!

http://blenderartists.org/forum/showthread.php?t=184777

http://blenderunderground.com/forums/vi ... =20&t=4370

Minifig
Posts: 1
Joined: Thu Aug 06, 2009 7:27 pm

Postby Minifig » Thu Aug 06, 2009 9:36 pm

Sorry if this was already mentioned, but have you tried vertex parenting?
http://www.blendenzo.com/tutVertexParenting.html
Please don't call me mini.

nowego4
Posts: 23
Joined: Sat May 22, 2010 10:42 pm

Postby nowego4 » Sat May 22, 2010 11:38 pm

Back to the original question, how to make the camera follow the ball, I once came across a game on BlenderArtists called Open Marble 1 by Jacob Baldwin. He had a dynamic empty with the logic on it (the logic made it move in directions, not rotate) but a ridged body ball that had a ball constraint to the empty. The camera was just parented to the empty. No python required. :D
Good luck!

bye
Even Macintosh isn't perfect. Unless you're comparing it to Windows.


Return to “Interactive 3d”

Who is online

Users browsing this forum: No registered users and 0 guests