Camera/Character Movement (MMORPG/WoW Like)

Hello,

this is extracted from here → http://forum.unity3d.com/threads/16949-WOW-Camera-Movement
a great thx to all other ppl in that thread who are working on that

i will keep this piece of code up-to-date
every time i change the code here, i will add the changes to the list

here is what i get so far.

  • the camera is moving back behind the player after moving around when the player was moving
  • selfattaching the player gameobject to the camera target
  • slower back and sidewalk
  • strafing (need to setup Input as “Strafing”)
  • run just on hold key (need to setup Input as “Run”)
  • public var “swimming” to reduce movementspeed by 70% when triggert
  • left right mousebutton moving, also sidebutton movetoggel (like wow) (setup Input as “Toggle Move” (“mouse 3” for my mx518 )
  • playerlayer avoid
  • camera softreturn while moving with mousesidebutton // v1.7 - 09.Oct.2012
  • added full movement list for animation usage to CharacterController // v1.9 - 09.Oct.2012
  • codecleanup // v2.0 - 09.Oct.2012
  • stop movement on autorun(sidebutton toggle) when jump or move back/forward // v2.1 - 09.Oct.2012
  • stop automovement on L+R Mousebuttons (sidebutton toggle) // v2.2 - 09.Oct.2012
  • fixxed the bug that doubels the movementspeed *// v2.3 - 19.Sep.2013

what u need to setup to get this running.
0. the Player/whatever u want to move needs a CharacterController (Unity->Component->Physics)

  1. the Main Camera needs to be tagged as MainCamera
  2. the Player/whatever u want to move needs to be tagged as Player
  3. the player needs to be added to a seperate layer
  4. on the attached CameraController script u need to deselect the Layer from 3. at “collisionLayers
  5. the CharacterController script needs to be attached at the Player/whatever u want to move
  6. the CameraController script needs to be attached at the Main Camera
  7. “fix” for the clipping problem with the MainCamera. :
  • go to MainCamera → Camera → Clipping Planes → Near and set it to 0.01
  • go to MainCamera → Camera → Field of View and set a value around 70 (it looks good)- 12.Oct.2012
  1. Example Project - 16.Oct 2012

!! have fun with it and thx to all the other ppl who are working on this scripts !!
and here is the code :slight_smile:

I had some free time and wrote a small website for it :slight_smile: there u will find Version 2.3 of the character controller,
screenshots how to use the scripts, a playable webbrowser demo and some more details :slight_smile:

http://ruhrnuklear.de/fcc/

Nice Job. The cd works like a charm, and so does the lerping back to pos.

I’m sure many will beg for a js version. (like me lol)

Your code-fu is strong grasshopper.

thx

"Your code-fu is strong grasshopper. "
hehe i know… i will add a js and a cs version in the next days, clean the code and do some better comment (as far as my english allows that ^^)

I added the scripts in JS and CS with code and for download also i made a codecleanup and corrected some “misstakes” and added some new futures (movements for animation)

Hey, this script is nice. I wanted to show you a video of my results though. I love the acute control of the camera, very nice. But when I run up or down terrain, the camera snaps in and out. Check this video

So, to be clear. My player is tagged as Player and also on another layer of Player. The camera is attached to my MainCamera. But the target is actually a childed game object called CameraTarget. Its really right behind the player. I got the same results when making the target the Player as well. Thanks

I had that problem too, i solved it by adding the layer.

thats a problem that there is still a gameobject between u and the camera that is not in the layer player layer, maybe try to place the camera and the player in the hirachy root without beeing in other gameobjects

"My player is tagged as Player and also on another layer of Player. The camera is attached to my MainCamera. But the target is actually a childed game object called CameraTarget. Its really right behind the player. I got the same results when making the target the Player as well. Thanks "

i didn’t understand that fully…
My player is tagged as Player and also on another layer of Player. So u mean the Player is on the Layer Player ?
The camera is attached to my MainCamera Did u mean the camera script or that the camera is part of a gameobject that is tagged as maincamera?

i have a gameobject and in it the player mesh with all the animation stuff and subobjects
my camera is tagged as MainCamera and in the Hierarchy root without anything else

they must be a gameobject between the gameobject tagged “Player” and the MainCamera tagged “MainCamera” that is not added to the Layer “Player”
that is all what i can tell u so far

moving the camera into the root hierarchy seemed to do the trick. I had it as a child of the player and it was assuming the Player layer as well. THanks for the tips. And great work, This is a nice, easy to use AND understand camera. Love it

Oh dear… it could be so easy XD

what i didn’t get running is that the camera didn’t move under the terrain :/… maybe someone can help on this

solved…
go to the maincamera, under camera set → Clipping Planes → Near to “0.01”

With this my “underworld” is perfect hidden :wink:

first post updated

We have this messages,

UnityException: Input Axis Toggle Move is not setup.
To change the input settings use: Edit → Project Settings → Input
CameraControllerjs.LateUpdate () (at Assets/WowoThree/CameraControllerjs.js:66)

UnityException: Input Axis Run is not setup.
To change the input settings use: Edit → Project Settings → Input
CharacterControllerjs.Update () (at Assets/WowoThree/CharacterControllerjs.js:32)

What controls shall we set on the project?

Thanks

The Message says all what u need :wink:

Got to → Edit → Project Settings → Input

Under Axes u see the Line “Size” increase the value by 2
now on the bottom of the list u see the last Action 3 times, open the last one and name it “Toggle Move” and set the “Positive Button” to any key u want for it (“mouse 3” for me- sidebutton)

do the same with the other duplicated entry and name it “Axis Run” and set the “Positive Button” to any key u want for it (“left shift” for me)

I added a example Project

Had a quick look at the example project and it looks great so far but I had to make one small change to the strafing code…

on line 67 of the V2.2 Character Controller the strafing negative key is “q” (in the example project) but the code was also subtracting creating a double negative and basically making the controller go right instead of left.

was this:

moveDirection.x -= Input.GetAxis("Strafing");

changed to this:

moveDirection.x += Input.GetAxis("Strafing");

Please correct me if I’m wrong as I’ve only been awake for 10 minutes :slight_smile:

Thanks for sharing this work

uups… u are right… i made this project very fast at work and didn’t test it

i uploaded a new example project were i switched the keys, don’t want to change the scripts

thx for the hint

Hello - just wanted to pop in and say I am using the latest version of your java scripts and they are working great. Thank you very much for the hard work on this.

thx a lot but its not only my work :wink:

All this is not working for me. i been adding inputs for the past hour with no help and still does not work for me.

Thank you to all those who worked on this
I haven’t looked at the post in forever and happened to see it in the forums today

Very nice job

““Only problem I am having is that when I jump while moving the camera zooms all the way into the player and then jumps back out really fast
Not sure if that explains it well or not but it seems the camera shouldn’t zoom in out out at all while jumping””

Did I set something up wrong or what haha

EDIT: Jumping problem due to tagging issue with my stand in character
He is made in Maya out of a couple cubes and spheres and all of them weren’t tagged as Player

Just would like to say thank you again for sharing this publicly

EDIT:
Still wondering wth "4. on the attached CameraController script u need to deselect the Layer from 3. at “collisionLayers” is supposed to mean

Most of these instructions aren’t very clear

chrisx84, could u give me more infos whats not working :wink:

Nubz,
3. the player needs to be added to a seperate layer
4. on the attached CameraController script u need to deselect the Layer from 3. at “collisionLayers”

that mean u have to add the player to a seperate layer and then deselect this layer in the CameraController script under the option “collisionLayers”

I got it straight in my head long enough to get it working after I looked over the example again right after posting that
Thanks for the reply

I had another thing in mind to ask you

This doesn’t handle animations at all correct?

Meaning I would have to write a script for it?

Thanks alot the controller is so smooth and works as described.

Robert