Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Blankzz · Jul 12, 2011 at 04:37 PM · c#cameracontrollerthird-person

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by aldonaletto · Jul 15, 2011 at 03:59 AM

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).

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Blankzz · Jul 15, 2011 at 12:05 PM 0
Share

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 :)

avatar image Blankzz · Jul 15, 2011 at 12:28 PM 0
Share

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?

avatar image aldonaletto · Jul 15, 2011 at 03:02 PM 0
Share

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;
avatar image Blankzz · Jul 15, 2011 at 03:19 PM 0
Share

Thanks again. I appreciate your detailed answers. $$anonymous$$akes 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.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Issue with my camera controls 0 Answers

Third Person Platformer Controls 0 Answers

Rotating Camera around player object 0 Answers

How to pan camera based on mouse position 0 Answers

How to rotate camera diagonally over players shoulder while still facing towards players direction 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges