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 thomasgriffin · May 19, 2020 at 10:34 PM · endless runnerobstaclespeed up

How do I increase the speed an instantiated object spawns in with?

Hi everyone, I am trying to make an endless runner game where the player stands stationary on a platform, and objects are instantiated in different patterns further down the platform with an initial speed. I want those objects to increase their speed after a certain time interval is met. For example, if the time interval was 30 seconds and the baseline speed was 10, I would want the speed to go to 20 after 30 seconds have passed, then increase to 30 after another 30 seconds have past, etc. I have a spawner spawning in obstacle patterns with spawn points in various areas.


As of right now, the obstacles spawn in with the same speed no matter what, but increase their speed once they've been spawned in for the duration of the time interval. For example, object 1 is spawned in, moves for 5 seconds at the initial speed, then increases speed, followed by object 2 which does the exact same thing as object 1 upon spawning. Here is my object movement code:

 using UnityEngine;
 
 public class ObstacleMovement : MonoBehaviour
 {
     public Rigidbody rb;
 
     // Keeps track of the time and increases speed based off the time
     float time;
     int seconds;
     public int timeInterval; // Time interval where speed is increased
 
     // Speed stuff
     public Vector3 speedInc; // Speed increase each time interval
     public float initialSpeed; // Initial speed in the Z direction
     Vector3 currentSpeed; // Current speed of the object
 
     // Vars for locking the object in place so no rotation/sliding occurs
     float startPositionX;
     Quaternion startRotation;
 
     // Start is called before the first frame update
     void Start()
     {
         startPositionX = transform.position.x;
         startRotation = transform.rotation;
 
         
         currentSpeed = new Vector3(0, 0, initialSpeed);
         rb.velocity = currentSpeed;
         
     }
 
     // Update is called once per frame
     void Update()
     {
         
         TrackTime();
         if (seconds == timeInterval) {
             currentSpeed = SpeedUp(currentSpeed);
             time = 0;
         }
         rb.velocity = currentSpeed;
 
         Debug.Log("Speed is: " + currentSpeed);
         
         LockPos();
     }
 
     Vector3 SpeedUp(Vector3 iSpeed) {
         Vector3 newSpeed = iSpeed + speedInc;
         Debug.Log("Speeding up");
         return newSpeed;
     }
 
     void TrackTime() {
         time += Time.deltaTime;
         seconds = (int)time % 60;
         Debug.Log(seconds + " seconds have past");
     }
 
     void LockPos() {
         Vector3 pos = transform.position;
         pos.x = startPositionX;
         transform.position = pos;
         transform.rotation = startRotation;
     }
 }
 

In the code above I am creating a timer, keeping track of the seconds, and then increasing the speed after XXX seconds have passed. What am I doing wrong? I can post the code of the spawner and spawn points if that's necessary. Is there a more appropriate place for this to be executed? Thanks!!

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

125 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 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 can I make Random Obstacle Spawn randomize between 4 or more prefabs? 2 Answers

Random Obstacle Placement 0 Answers

random obstacle generator 2 Answers

Spawn Different Obstacles for certain platforms 1 Answer

UnitySteer, obstacle avoidance, and wide vehicles 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