x


3rd Person Camera & Controller C#

Hi

Does anybody know if I can get the 3rd person camera and controllers that ship with unity in c#. Eventually I will create my own but I would like to use the one that ships with unity for a quick prototype. I've made an on screen thumbstick that holds its own axis values so I need to modify the script so that it takes my thumbstick axis values instead.

more ▼

asked Jul 12 '11 at 04:37 PM

Blankzz gravatar image

Blankzz
246 19 20 23

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I don't believe someone have translated both scripts to C# - they are too complex, and the translation would be a typical too pain, no gain case. But you can modify the ThirdPersonController.js script to use your thumbstick:

1- Create a new folder at Assets and place your C# script there - this enables it to "see" the ThirdPersonController script.

2- Modify your script to copy the axis values to two static vars located at the ThirdPersonController script:
ThirdPersonController.axisH and ThirdPersonController.axisV

3- Add the two lines below at the beginning of the ThirdPersonController script:

   static var axisH: float = 0;
   static var axisV: float = 0; 

4- Locate the two lines below:

   var v = Input.GetAxisRaw("Vertical");
   var h = Input.GetAxisRaw("Horizontal");

and change them to:

   var v = axisV;
   var h = axisH;

This is enough to do the basic movements with your thumbstick, but doesn't include the Shift or Jump keys - you must use the keyboard shift and your thumbstick to make the character run, and the Jump key at the keyboard to make it jump. If you have equivalents to these commands in your thumbstick, use the same logic to implement them in the ThirdPersonController (search for Input.GetKey for the shift, Input.GetButton for the jump).

more ▼

answered Jul 15 '11 at 03:59 AM

aldonaletto gravatar image

aldonaletto
41.6k 16 42 197

Hi aldonaletto. I understood which values to change but I think I got confused with which way round my unityscript and c# scripts could communicate. I thought it was the other way round so thanks for that :)

Jul 15 '11 at 12:05 PM Blankzz

Just a quick question. Shouldn't I need to put the class name before the axis values to access them and do they have to be static for them to be accessed?

Jul 15 '11 at 12:28 PM Blankzz

1- Communication between JS and C# is a problem because they do not "see" each other at compiler time. Once compiled to CIL (the .NET Commom Intermediate Language), however, their static variables become visible to other scripts not compiled yet (maybe static functions too, but I'm not sure). Since you've placed your C# script in a non-standard folder, it will be compiled last, what enables it to "see" the static variables of all already compiled scripts - no matter if C# or JS (or Boo, if someone in this planet use it). But the already compiled scripts don't see your script, so this is a one-way communication line.

2- Static variables can be accessed as scriptName.variableName by other scripts. Non-static variables of other scripts should be accessed via GetComponent, but I'm not sure if it would work in this case (mixed C# and JS), even in the right compiling order. You can access these variables in your C# script doing this:

  ThirdPersonController.axisH = myHAxis;
  ThirdPersonController.axisV = myVAxis;
Jul 15 '11 at 03:02 PM aldonaletto

Thanks again. I appreciate your detailed answers. Makes sense to me now. I think developers who sell in the asset store should be encouraged to make their scripts available in multiple languages, otherwise I can see this causing problems.

Jul 15 '11 at 03:19 PM Blankzz
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4179
x3015
x526
x90

asked: Jul 12 '11 at 04:37 PM

Seen: 3450 times

Last Updated: Jul 15 '11 at 03:19 PM