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
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