Jump to content

My 3rd Person Character Controller


#1
Clackdor

  • Developer
  • PipPipPip
  • 170 posts
W - forward
S - backward
A - turn left
D - turn right
1 - Sword Swing (no sword model loaded, though)

Mouse right click to turn your character with the mouse.
Mouse left click to look around, but not change direction.

Attached Files



#2
Engineer Ken

  • Developer
  • PipPipPip
  • 201 posts
Cool. Now you just gotta do the camera object avoidance. Use raycasts, don't give ur camera a physics body.

XD

#3
Clackdor

  • Developer
  • PipPipPip
  • 170 posts
Got it. Replace character.exe in the zip with this one.

Attached Files



#4
Josh Klint

  • Staff
  • 3,309 posts
I would use the Curve() function to make the camera gradually align to match the player's direction when they turn.
Thank you for helping me help you help us all.

#5
Engineer Ken

  • Developer
  • PipPipPip
  • 201 posts
Hi Clackdor,

Very good I see you have some decent object avoidance. There are just a few things I'd like to point out. Tree of them is really easy to fix. The other not so.

1. The camera can go upside down. Try limiting the X rotation of the camera
Attached Image: shot2.jpg

2. Your collision with the floor is very good. However you don't have many walls in your scene so you may not have noticed that if you get too close to a wall the wall disappears. I managed to position the camera against the structure to show what I mean. As you can see some of the structure is invisible and the camera is looking through this. I don't know if there are any conventional ways of solving this but I came up with a way myself. Check my youtube channel for Third Person Camera stuff I think I explain it somewhere in there.
Attached Image: shot1.jpg

3. What Josh said. Curve() should not be too hard to implement

4. Character needs to strafe. Difficult to position the character freely without a strafe left and strafe right option.

Otherwise its coming along very nicely. My camera is not perfect but I think it is good enough for now and I'll make it better after I program some gameplay. I'd suggest just do points 1, 3 & 4 and then move on to something else for now. Point 2 will be necessary in the long run but its not generally a quick fix and may take some time.

#6
Clackdor

  • Developer
  • PipPipPip
  • 170 posts
Thanks a lot for this feedback, Ken!

I will play around with the camera collision some more. It's only been implemented for a day.

The strafe code is actually commented out. This character doesn't have a strafe animation. I'll have to add it.

I also need to reverse the walking animation so it looks more correct when she is walking backwards.

#7
cassius

  • Developer
  • PipPipPip
  • 604 posts
I have been struggling with how to stop my camera passing thru walls and obscuring the view.In one commercial game I have this problem is solved by raising the viewpoint of the camera when near walls so that it looks down on the character from above then going back to eye level as the camera moves away from walls.

Can someone direct me to a code example??
Intel 7200 2.5 ghz GeForce 9800gt (1Gb) 2Gb Mem Win 7 32 bit
Gimp Bmax uu3d Ac3d Paint.net 3dws Blender Hexagon silo

#8
Clackdor

  • Developer
  • PipPipPip
  • 170 posts
Taken directly from my source.

pivot2 is an entity that is on a line between the character and camera, but positioned a little ways out so that the ray does not hit the character mesh. It basically makes a circle around the character mesh.

Because the TPick raycast collision location is given in global coordinates, I position a pivot3 at that location instead of doing Vec3 math and figuring out local/global conversion.

if (EntityPick(&raycast,pivot2,10.0f,1)) {
        PositionEntity(pivot3,Vec3(raycast.X,raycast.Y,raycast.Z));
        PositionEntity(camera, Vec3(0,0,Min(camz, EntityDistance(controller,pivot3)-0.7f)));
    }
    else {
        PositionEntity(camera, Vec3(0,0,camz));
    }

FYI, I decreased the frequency of the images shown in number 2 of Ken's comments by adding that 0.7f modifier shown above and also adjusting my near camera frustum range to 0.01.

#9
Eagle

  • Developer
  • PipPipPip
  • 117 posts
Now this is really cool!!! This was so sweet of you Clackdor, thank you so much~

Always~
Vickie ;)

#10
gamecreator

  • Developer
  • PipPipPip
  • 191 posts
I'm guessing you have Flip(1) in your code. tkunze found that it makes it so the game doesn't update for me unless I move the window.

#11
Engineer Ken

  • Developer
  • PipPipPip
  • 201 posts

View Postgamecreator, on 18 January 2012 - 05:04 AM, said:

I'm guessing you have Flip(1) in your code. tkunze found that it makes it so the game doesn't update for me unless I move the window.

Huh? Flip(1) means v-sync is on. Flip(0) v-sync is off

Also Clackdor you can completely eliminate pic number 2 if you use multiple raycasts. as shown in the following picture:

Attached Image: Camera Object Avoidance.jpg
Note: When I say in the pic fire 4 'arrays' I actually mean ray-casts lol.

Off course this is just my method and by no means the only way. However, it does eliminate any possibility of things being clipped on the sides above and below.

#12
Rick

  • Developer
  • PipPipPip
  • 2,973 posts
When I was doing mine some time ago I would move the camera toward the player by just a little after the pick to avoid clipping into geometry.
Pi Lua Scripts
http://good-vs-bad.blogspot.com/

"Our deepest fear is not that we are inadequate. Our deepest fear is that we are powerful beyond measure. It is our light, not our darkness that most frightens us. We ask ourselves, who am I to be brilliant, gorgeous, talented, fabulous? Actually, who are you not to be?"

#13
Clackdor

  • Developer
  • PipPipPip
  • 170 posts
I did what Rick did. I will play around with your suggestion, though, Ken. It's not too bad now, except when the character backs right against a wall.

I've also moved on to focusing on other gameplay elements and shooting for a first game release this spring. It's sort of a stupid pac-man game that Rick gave me the idea for a while ago, but it does do a good job of exercising the old programming joints and getting used to Leadwerks commands.

#14
gamecreator

  • Developer
  • PipPipPip
  • 191 posts

View PostEngineer Ken, on 18 January 2012 - 11:14 AM, said:

Huh? Flip(1) means v-sync is on. Flip(0) v-sync is off
Yup, that's it. I can make a video if you want to see it in action.

#15
Engineer Ken

  • Developer
  • PipPipPip
  • 201 posts

View Postgamecreator, on 19 January 2012 - 07:41 AM, said:

Yup, that's it. I can make a video if you want to see it in action.

No that's fine. I know what it does. I'm just confused by what you were saying.

"the game doesn't update for me unless I move the window"

not sure I understand what you mean by that because it sure doesn't do that on my computer. Probably just a misunderstanding lol

#16
gamecreator

  • Developer
  • PipPipPip
  • 191 posts
I run the game. It seems frozen. I press the buttons to move. Nothing seems to happen. I then move the window. The window updates to the current frame - no animation, just jumps from the old to the current one. Press more buttons. Nothing moves. But as soon as I move the window it updates again. I'm probably one of very few people who this happens to.

#17
Marleys Ghost

  • Developer
  • PipPipPip
  • 1,906 posts

View PostClackdor, on 18 January 2012 - 02:09 PM, said:

I did what Rick did. I will play around with your suggestion, though, Ken. It's not too bad now, except when the character backs right against a wall.


Which is why using a single cast followed by a camera move forward will not eliminate clipping, it may reduce it on some flat surfaces but posts and pillars are a different matter, and as you know when the 3rd Person character is close to, for example a wall, you will find the camera inside the characters head looking out. I use an array similar to that in Kens illustration.
AMD Bulldozer FX-4 Quad Core 4100 Black Edition
2 x 2GB DDR3 1333Mhz Memory
Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5
Windows XP Home SP3

BlitzMax 1.45 • MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro
AC3D • ShaderMap Pro • 3DWS • ADN - Gimp & Paint.NET

LE 2.5 • UDK • CE3 SDK • Torque 3D Pro 1.2 • Unity 3.4.2 • AGK

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

#18
Engineer Ken

  • Developer
  • PipPipPip
  • 201 posts

View Postgamecreator, on 22 January 2012 - 12:04 AM, said:

I run the game. It seems frozen. I press the buttons to move. Nothing seems to happen. I then move the window. The window updates to the current frame - no animation, just jumps from the old to the current one. Press more buttons. Nothing moves. But as soon as I move the window it updates again. I'm probably one of very few people who this happens to.

Oh wow. Thats odd :(

#19
Eagle

  • Developer
  • PipPipPip
  • 117 posts
Awww, there is no way to use it on our own games? :(

#20
Clackdor

  • Developer
  • PipPipPip
  • 170 posts
I'm afraid it needs some refinement before I can release it. I would also need to define some parameters, for instance, its a player controller/animation controller. Should I separate those out? Plus, so many people are quirky about their controller, that I might just consider throwing out there as a code dump for others to edit to fit their needs. But it seems like most developers write their own.