3rd Person Camera

A forum to store posts deemed exceptionally wise and useful
Post Reply

What do you think of the camera?

Great!!
33
46%
Good
25
35%
Bad
7
10%
Terrible
7
10%
 
Total votes: 72

Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

3rd Person Camera

Post by Boogle »

Well I was bored at school today so I decided to write a basic 3rd person camera, using Star Wars Galaxies style controls. For those who don't know what the control is like, basically there is a small box area in the center of the screen where the mouse is free to move. If it moves outside of this box the camera rotates around the character.

You can download the project here: http://members.rogers.com/jamiegoodfell ... Camera.zip
or the Exe here: http://members.rogers.com/jamiegoodfell ... eraExe.zip

After downloading, copy sydney.bmp, sydney.md2, and map-20kdm2.pk3 to your project's working directory, or the same directory as the Exe. You'll also have to get irrlicht.dll yourself, version 0.4.2 (Don't want to waste too much of my web space). There's no error checking or anything, so the executable will crash if these aren't in the correct location.

Controls are:

Mouse movement: rotate camera
+/- keys: Zoom in/out
Arrow Keys: Move Sydney

Caveat: You have to hold down the arrow key for a second or two before Sydney really starts to move. I just hacked together some movement code after finishing the camera code to get everything working, so movement isn't the greatest.
hell_bird
Posts: 18
Joined: Mon Nov 03, 2003 12:30 pm

Post by hell_bird »

very good!!!

i think you have only to work on small things... as you said : the movement of sydney is poop. then: if i move my mouse to the left side i want sydney to turn left. A big "bug" is, that if you look on the bottom, sydney wont move very much. anyway think you did it quite well.

i think if it becomes part of the engine it woud be better if it doesn't do evervthing for the user. maybe a function, that calculates the camera position out of 2 parameters (mousex,y). some people maybe don't want to use the engines mouse-input (low precition)
buhatkj
Posts: 444
Joined: Fri Dec 12, 2003 4:53 am
Contact:

hrm, didnt wanna run...

Post by buhatkj »

well i havent tried recompiling it yet, but the exe didnt wanna run for me. i copied all the files you mentioned into the directory i extracted it to. dunno...

i also have a 3rd person cam in FMORG, my project, but mine instead rotates with the arrow keys. one of the thing i can tell you is that one reason you might have to wait a sec for her to really move is because it is waiting on the key repeat. you can see if you look in my event receiver class in fmorg, that the keydown event simply switches the movement on, and the keyup switches it off. the movement iteself is done by a function i call during the render loop.
this may not be the best way to do it, it prolly slows down my render loop for it to jump out and do that during, but i still get a respectable FPS with it...

-Ted
My irrlicht-based projects have gone underground for now, but if you want, check out my webcomic instead! http://brokenboomerang.net
qwe
Posts: 112
Joined: Sun Dec 28, 2003 12:54 am
Location: Oregon, USA

Post by qwe »

This is something I've been trying to do. Now, does anyone know how to put a Jedi Outcast-style crosshair in? basically, there's a crosshair in 3rd person as well as first person.

any ideas?
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post by Boogle »

Hell_bird: I am soon going to make a second style of 3rd person camera that is more like a Tomb Raider style 3PC, so it will always stay behind the character. Hopefully I'll get it to flow nicely so if the character turns too quickly the camera will lag a bit. I think I know how I can fix the syndey not moving much if looking from the bottom issue. I'll look into the Sydney always facing forward thing as well.

Buhatkj: Are you using the irrlicht 0.4.2 VisualStudio dll? Also, you are correct about the keyboard inputs lagging. I wasn't too woried when doing the movement since the main thing I wanted to present was the camera movement itself.

qwe: This has been done by somebody else, if you search the forum you should be able to find details. But basically, just hide the cursor, and stick a crosshair image in its place (using a GUI element). Every frame, update the image's location based on the mouse's current location. Since my animator repositions the mouse immediatly after a scene draw, you shouldn't have to worry about the image jumping outside of the inner box (as the cursor does sometimes).
Byron
Posts: 8
Joined: Tue Jan 06, 2004 11:47 pm

Fixing sydney moving

Post by Byron »

If you want to fix the movement of sydney so that she responds right away dont do the movement and animation in the event receiver, put it all in function that is called from the game loop. In the event receiver just set variables such

Code: Select all

if(event.KeyInput.Key == irr::KEY_UP)			
{
       if(event.KeyInput.PressedDown)
	      sydney->setForward(true);  // set forward sets a variable
       else			       // bool move_forward
	      sydney->setForward(false);
}

then have a function that you can call from the game loop:

void animate()
{
         if(move_forward)
                forward();	// forward() sets anim to run and moves node 

         /// etc  check for rest of conditions
}              
	
this will get rid of the little delay between when the anim starts and the char runs. I do all this in classes of course with class private variables.

I also wrote a better collision detection for firing my weapons. In the techdemo the way firing is done assumes that a bullet hits the target as soon as you shoot. If you have a slower projectile you will hit the player even though they have moved out of the way when the bullet actually gets there.
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post by Boogle »

Cool thanks. However I'm going to create a SceneNodeAnimator for character movement as well, and do it that way. It'll have similar code to what you've given, but I won't have to worry about code in the game loop once it's attached.
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post by Boogle »

Alright, I've updated the zip files, the links are still at the top of this thread. I've fixed the bugs Hell_bird mentioned, fixed up Sydney's movement so it is smooth (I did this using another SceneNodeAnimator, it should be easily extensible, feel free to use it), and added some quick crosshair code as a demo for qwe. Let me know if you think of some other improvements it could use.
qwe
Posts: 112
Joined: Sun Dec 28, 2003 12:54 am
Location: Oregon, USA

Post by qwe »

here are my thoughts on the subject.

There's bug where left/right on the mouse are inverted, i.e. when you move the mouse left, the character turns right, etc.

I don't think the mouse is reponsive enough, but that's just opinion.

When you hit the down arrow, the character should walk backwards, not turn around and walk into the camera.
Guest

looks good

Post by Guest »

Yeah that looks good now, I agree with the backwards thing and the mouse axis buts maybe thats the way you intended it, and it would be easy to change anyway.
I think that will help alot of people who were posting about getting thier 3rd person camera!
Byron
qwe
Posts: 112
Joined: Sun Dec 28, 2003 12:54 am
Location: Oregon, USA

Post by qwe »

I also think the crosshair should be where the character is pointing, not the mouse pointer...
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post by Boogle »

Yes, the character movement and crosshair position are where I intended them to be. The character doesn't turn at all when you move the mouse, the camera rotates around the character.. so when you move the mouse left, it rotates leftward around the character.

To make the mouse more reponsive in your own projects, just set the mouse speed value in the animator constructor.

As I said, I made the camera and player movement to mimic Star Wars Galaxies. I will make another one (perhaps Wednesday when I'm stuck at school with nothing to do again) that mimics Tomb Raider style controls, which will have the character move backwards when pressing down, have the camera look where the player is looking, etc.
powerpop
Posts: 171
Joined: Thu Jan 08, 2004 1:39 am
Location: san francisco

Post by powerpop »

Boogle - great work - i think one of the strengths of irrlicht will be these addable classes - it would be great if we can keep them relatively self contained, simple and updated - Niko, do you think there could be a place on the server to host them and a page to list them? - if not i might be able to do so on my ping.net server - and i would be willing to organize the object list

objects i have seen so far:

- Boogles camera code as above

- fmorgs player character object (and possible an npc as a subset of this)

- 2D library (is this going to remain separate Niko or will it be incorporated into the core of irrlicht?)

i imagine there are others i have yet to see in the forums
powerpop
Posts: 171
Joined: Thu Jan 08, 2004 1:39 am
Location: san francisco

Post by powerpop »

hmm Boogle, your player class is nice as well ...
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post by Boogle »

Why thank you :)

I set up the keymap stuff so you can easily add more functions such as jumping, crouching, etc.
Post Reply