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 /
  • Help Room /
This question was closed May 03, 2017 at 10:41 PM by Drew7398 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Drew7398 · Apr 14, 2017 at 02:20 AM · endless runnerpowerupspeed up

How to speed up player character in ENDLESS RUNNER after colliding with powerup??

I'm making a 3D endless runner game inspired by Subway Surfers. Thus, as you can guess, the character is constantly running until death. The thing is, I want the player character to run FASTER after colliding with a powerup, but I don't know how to go about doing this. Could someone help? I've been following a great tutorial series by Game Design HQX on YouTube. https://www.youtube.com/watch?v=s0X4_zT5R_s Here is my script. Please be specific on what I should change/add in it as I am still relatively new to C# scripting. Thank you.

Note: I named my character Joe, hence the script name.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class moveJoe : MonoBehaviour {
     public KeyCode moveL;
     public KeyCode moveR;
     Rigidbody playerRigidbody;
     public int laneNum = 2;             //this indicates what "lane" of the path the character is on (2 meaning middle, 1 meaning left, 3 meaning right)
 
     public string controllocked = "n";  //the character can move to another adjacent lane if he is in the middle lane 
 
 
     public float horizVel = 0;    //the character will remain in the middle lane unless 'A' or 'D' is pressed
 
     // Use this for initialization
     void Start () {
 
         playerRigidbody = GetComponent<Rigidbody>();
        
     }
     
     // Update is called once per frame
     void Update () {
         GetComponent<Rigidbody>().velocity = new Vector3(horizVel, 0, 4);
 
         if((Input.GetKeyDown(moveL))&&(laneNum>1)&& (controllocked == "n"))
         {
             horizVel = -4;
             StartCoroutine(stopSlide());
             laneNum -= 1;
             controllocked = "y";
 
         }
 
         if ((Input.GetKeyDown(moveR))&&(laneNum<3) && (controllocked == "n"))
         {
             horizVel = 4;
             StartCoroutine(stopSlide());
             laneNum += 1;
             controllocked = "y";
         }
     }
 
     void OnCollisionEnter(Collision other)         //this is when the character collides with an incoming car
     {
         if(other.gameObject.tag=="Lethal")
         {
             Destroy(gameObject);
             
         }
     }
     IEnumerator stopSlide()
     {
         yield return new WaitForSeconds(.5f);
         horizVel = 0;
         controllocked = "n";
     }
 
     private void OnTriggerEnter(Collider other)         //the powerup deactivates after the character collides with it 
     {
        if(other.gameObject.tag=="Pick Up")
        {
             other.gameObject.SetActive(false);
             
 
 
         }
     }
 
    
 }
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

  • Sort: 

Follow this Question

Answers Answers and Comments

98 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

Related Questions

Speed Increase Power up 1 Answer

Change Gravity on falling objects 1 Answer

C# how to make things happens Through time? 0 Answers

Help: Assets/scripts/Gamemaneger.cs(34,9): error CS0428: Cannot convert method group `FindObjectOfType' to non-delegate type `PlatformDeystoyer[]'. Consider using parentheses to invoke the method 1 Answer

Error CS0246: The type or namespace name 'ChallengeController' could not be found. 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