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 dominoslex3 · Jun 12, 2017 at 07:31 PM · scripting problemcharactercontrollerscripting beginnercharacter movementendless runner

The character controller stop moving when the Speed Start increase Endless runner

this is the class for player movement

using UnityEngine; using System.Collections;

public class PlayerMotor : MonoBehaviour {

  private CharacterController controller;
  private Vector3 moveVectore;
  private float animationDuration = 0.2f;
  public float speed = 0.01f;
  private float verticalVelocity = 0.0f;
  public float gravity = 12.0f;
  public float jumpForce = 20.0f;
  public float speedH = 20f;
  private Vector3 left = new Vector3(-4, 0, 0);
  private Vector3 right = new Vector3(4, 0, 0);
  private bool isDeath = false;
  void Start()
  {
      controller = GetComponent<CharacterController>();
   
  }
  void Update()
  {
      if (isDeath)    
      
          return;  
      
      if (Time.time < animationDuration)
      {
          controller.Move(Vector3.forward * speed * Time.deltaTime);
          return;
      }
      if (controller.isGrounded)
      {
          verticalVelocity = -gravity * Time.deltaTime;
          if (Input.GetKeyDown(KeyCode.Space))
          {
              verticalVelocity = jumpForce;
          }
      }
      else
      {
          verticalVelocity -= gravity * Time.deltaTime;
      }
      Vector3 moveVector = Vector3.zero;
      //X
     
      if (Input.GetKeyDown("left"))
      {
          controller.Move(left);
      }
      if (Input.GetKeyDown("right"))
      {
          controller.Move(right);
      }
      //Y
      moveVector.y = verticalVelocity;
      //Z
      //  moveVector.z = Input.GetAxis("Vertical") * 5.0f;
      
      controller.Move(Vector3.forward * speed);
      controller.Move(moveVector * Time.deltaTime);    // here when i delete this function the character controller is continue the moving , but the jump don't  working
  }
  public void SetSpeed(float modifier)
  {
      speed = 0.5f + modifier;   
  }
  private void OnControllerColliderHit(ControllerColliderHit hit)      
  {
      if (hit.point.z > transform.position.z + controller.radius)
          Death();
  }
  private void Death()
  {
      isDeath = true;
      GetComponent<Score>().OnDeath();    
  }



}

and this class for Score

using UnityEngine; using System.Collections; using UnityEngine.UI;

public class Score : MonoBehaviour {

  private float score = 0.0f;
  public Text scoreText;
  public float difficultyLevel = 1f;
  private float maxDifficultyLevel = 2;
  private float scoreToNextLevel = 2;
  private bool isDead = false;
  // Update is called once per frame
  void Update ()
  {
     if (isDead)  
          return;
      if (score >= scoreToNextLevel)
          LevelUp();
      
      score += Time.deltaTime;
      scoreText.text = ((int)score).ToString();
  
  }
  void LevelUp()
  {
     
      if (difficultyLevel == maxDifficultyLevel)
      {
          return;
      }
     // scoreToNextLevel *= 2f;
      difficultyLevel+=0.1f;   
      GetComponent<PlayerMotor>().SetSpeed(difficultyLevel);  
  }
  public void OnDeath()
  {
      isDead = true;
  }

}

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

112 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Boosting Character Controller Problem 0 Answers

Fliping character 180 degrees when moving left 1 Answer

Player acts weirdly when I release movement input 0 Answers

Rotate the character movement with the character 1 Answer

My player is stuck on left and right side(Endless Runner) 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