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 appmonster · Aug 15, 2011 at 04:32 PM · movementcharactercontrollerplatformerbce0005

Moving platform and character controller

Hello,

I am having trouble trying to understand the scripting for moving my character controller along with a moving platform. I would like some help in trying to figure out how to get my character to move along with my moving/rotating platforms. I also keep getting the following errors:

Assets/Scripts/MoveAround.js(93,22): BCE0005: Unknown identifier: 'myCharacterController'. Assets/Scripts/MoveAround.js(93,50): BCE0005: Unknown identifier: 'calculatedMovement'.

Please find attached my script for my character:

 var speed : float = 6.0;
 var jumpSpeed : float = 8.0;
 var gravity : float = 20.0;
 var rotateSpeed : float = 3.0;
 private var moveDirection : Vector3 = Vector3.zero;
 private var dead = false;
 // Moving platform support
 private var activePlatform : Transform;
 private var activeLocalPlatformPoint : Vector3;
 private var activeGlobalPlatformPoint : Vector3;
 private var lastPlatformVelocity : Vector3;
 
 // If you want to support moving platform rotation as well:
 private var activeLocalPlatformRotation : Quaternion;
 private var activeGlobalPlatformRotation : Quaternion;
 
 
 
 function OnControllerColliderHit (hit : ControllerColliderHit)
 {
 
  // Make sure we are really standing on a straight platform
     // Not on the underside of one and not falling down from it either!
     if (hit.moveDirection.y < -0.9 && hit.normal.y > 0.5) {
         activePlatform = hit.collider.transform;    
     }
 
     if(hit.gameObject.tag == "fallout")
     {
         dead = true;
     }
 
 }
 
 function OnTriggerEnter( hit : Collider)
 
     {
     if(hit.gameObject.tag == "fireBall")
     {
         dead = true;
         Destroy(hit.gameObject);
     }
 }
 
 
 
 
 function Update() {
 
         
         if (Input.GetButton ("Jump")) { // of set it to jumpSpeed if Jump pressed
             moveDirection.y = jumpSpeed;
         }
     }
     // Apply gravity anyway
     moveDirection.y -= gravity * Time.deltaTime;
     // Move the controller
     controller.Move(moveDirection * Time.deltaTime);
 
 
  // Moving platform support
     if (activePlatform != null) {
         var newGlobalPlatformPoint = activePlatform.TransformPoint(activeLocalPlatformPoint);
         var moveDistance = (newGlobalPlatformPoint - activeGlobalPlatformPoint);
         if (moveDistance != Vector3.zero)
                 controller.Move(moveDistance);
         lastPlatformVelocity = (newGlobalPlatformPoint - activeGlobalPlatformPoint) / Time.deltaTime;
 
         // If you want to support moving platform rotation as well:
         var newGlobalPlatformRotation = activePlatform.rotation * activeLocalPlatformRotation;
         var rotationDiff = newGlobalPlatformRotation * Quaternion.Inverse(activeGlobalPlatformRotation);
 
         // Prevent rotation of the local up vector
         rotationDiff = Quaternion.FromToRotation(rotationDiff * transform.up, transform.up) * rotationDiff;
 
         transform.rotation = rotationDiff * transform.rotation;
     }
     else {
         lastPlatformVelocity = Vector3.zero;
     }
 
     activePlatform = null;
 
       var controller : CharacterController = GetComponent(CharacterController);
     transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
       // Calculate forth/back velocity vector
     var forward : Vector3 = transform.forward * speed * Input.GetAxis("Vertical");
     forward.y = moveDirection.y; // keep current vertical velocity
     moveDirection = forward; // but update horizontal velocity
        if (controller.isGrounded) {
         moveDirection.y = 0; // zero vertical velocity if already grounded
 
     collisionFlags = myCharacterController.Move (calculatedMovement);
 
 
     // Moving platforms support
     if (activePlatform != null) {
         activeGlobalPlatformPoint = transform.position;
         activeLocalPlatformPoint = activePlatform.InverseTransformPoint (transform.position);
 
         // If you want to support moving platform rotation as well:
         activeGlobalPlatformRotation = transform.rotation;
         activeLocalPlatformRotation = Quaternion.Inverse(activePlatform.rotation) * transform.rotation; 
     }
 
 
 }
 function LateUpdate()
 {
         if(dead)
         {
             transform.position = Vector3(-28,545.8922,-25.69122);
             gameObject.Find("Main Camera").transform.position = Vector3(-17.58673,603.5624,-86.56421);
             dead = false;
 }
 
 }
 
 // Require a character controller to be attached to the same game object
 @script RequireComponent (CharacterController)
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

0 Replies

· Add your reply
  • Sort: 

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

Audio for movement 1 Answer

Character controller wont move 1 Answer

Can someone help my character move correctly? 0 Answers

How to get our character controller script to make our player move? 1 Answer

Why is my character controller not working? 1 Answer


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