Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 crunchyoverseas · Jul 31, 2014 at 04:05 AM · cameracharactercontroller

Adding a Character Controller using c# script

Hello,

I'm trying to get a FPS controller to snap onto and off of any model on I have on my little chunk of test terrain. The FPS controller works great if you add it to a model and then adjust it manually in the window, but when you use addcomponent it seems to have some issues.

1) Model has to be far above terrain or it just falls through. So the model is floating and moving way above the terrain. 2) camera is at the models feet. 3) can't move the components or it just moves the model so can't figure out how to move the camera to face level.

Any ideas?

 using UnityEngine;
 using System.Collections;
 
 public class ToonControl : MonoBehaviour {
 
     GameObject small;
     GameObject medium;
     GameObject large;
 
     // Use this for initialization
     void Start () {
         small = GameObject.FindGameObjectWithTag ("small");
         medium = GameObject.FindGameObjectWithTag ("medium");
         large = GameObject.FindGameObjectWithTag ("large");
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void OnGUI () {
         GUI.Box (new Rect (10, 10, 120,110), "Possess Minion");
 
         if(GUI.Button (new Rect(30,40,80,20), "Small")) {
             camera.enabled = false;
             small.AddComponent<Camera> ();
             small.camera.tag = "MainCamera";
             small.AddComponent<CharacterController>();
             small.AddComponent<MouseLook>();
             small.AddComponent<FPSInputController>();
         }
 
         if(GUI.Button (new Rect(30,65,80,20), "Medium")) {
             camera.enabled = false;
             medium.AddComponent<Camera> ();
             medium.camera.tag = "MainCamera";
         }
 
         if(GUI.Button (new Rect(30,90,80,20), "Large")) {
             camera.enabled = false;
             large.AddComponent<Camera> ();
             large.camera.tag = "MainCamera";
         }
     }
 }
   
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
0

Answer by crunchyoverseas · Aug 02, 2014 at 06:41 PM

Stumped?

Okay, I'll give you the solution:

Create an empty gameobject with the same coordinates as your model. If you model is scale 6x6x6, make the scale of your empty gameobject something like 1x5x1. But you want the Y to be just a little smaller so you are at face level. Also make sure you rotated the correction direction. Add your model to the empty game object and it works. It will take some playing around to get it just right. But the collider will keep it from falling through the world and it won't be floating above the ground.

If I get some time I might post a small video on how to do it, I've several people ask the same question and not get an appropriate response back. I asked it like 3 times and finally got half an answer which allowed me to fill in the other half of the equation.

I really like the video tutorial section but I feel they should have some shorter, smaller videos where they just tackle some of these often asked questions. Unity should hire me to make those :)

Comment
Add comment · 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

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

2 People are following this question.

avatar image avatar image

Related Questions

Is there a way to make a Character Controller stop instead of move over obstacles?? 1 Answer

Character Controller being pushed or not colliding with Plane Collider 0 Answers

My character controller and vehicle (spaceship) move at same time 1 Answer

Third person camera; player rotation. 1 Answer

Launching a Character controller using vectors 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