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 medabots1996 · Jun 02, 2013 at 01:51 PM · animationmovecharacter controllerplatform

Character Keep On Moving Without Pressing Button

Hey everyone, so I'm new to Unity (It's my first time here) I would like to ask a small question My Player's using a Character Controller and Character Motor with 3rd Person Controller Today, I created a script for a simple platform system using UnityEngine; using System.Collections;

 public class MovingPlatformSystem : MonoBehaviour 
 {
     public Transform DestinationSpot;
     public Transform OriginSpot;
     public float Speed;
     public bool Switch = false;
     
     void FixedUpdate()
     {
         // For these 2 if statements, it's checking the position of the platform.
         // If it's at the destination spot, it sets Switch to true.
         if(transform.position == DestinationSpot.position)
         {
             Switch = true;
         }
         if(transform.position == OriginSpot.position)
         {
             Switch = false;
         }
         
         // If Switch becomes true, it tells the platform to move to its Origin.
         if(Switch)
         {
             transform.position = Vector3.MoveTowards(transform.position, OriginSpot.position, Speed);
         }
         else
         {
             // If Switch is false, it tells the platform to move to the destination.
             transform.position = Vector3.MoveTowards(transform.position, DestinationSpot.position, Speed);
         }
     }
 }

The system worked, but the problem is when my character (means the player) is sitting on the platform, he just keep on looping the walk animation without any button pressed. Thus, the animation became faster and slower based on the speed of the platform, so I think it must be a moving script causing the havoc! (And I thought that script must have interpreted the character's position changing as moving) So, could anyone help me with figuring out which script caused the whole problems? Thanks in advanced!

Comment
Add comment · Show 1
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 fueldown · Jun 03, 2013 at 07:00 PM 1
Share

why are you using moveTowards?? If you just want to move the transform, just use transform.Translate. Also, third argument in $$anonymous$$oveTowards is not speed. it is the distance that you want the transform to stop moving before it reaches the target position. This doesn't make any sense with what you are trying to achieve. Another point is, use if-else if ins$$anonymous$$d of two ifs.

 if(transform.position == DestinationSpot.position)
        {
          Switch = true;
        }
 else if(transform.position == OriginSpot.position)
        {
          Switch = false;
        }

Can you share the player script as well? This will help deter$$anonymous$$e the actual bug.

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

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How would I go about making an animation affected by this script? 1 Answer

Collision between Character Controller and Box Collider 2 Answers

Can I make animations snap to a frame? 1 Answer

Moving textures over a model 1 Answer

CharacterController.move Glider movement 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