Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Constant speed and tiles with speed boost

Discussion in '2D' started by Cederskog, Jan 17, 2018.

  1. Cederskog

    Cederskog

    Joined:
    Jan 17, 2018
    Posts:
    1
    Hello,

    Is there any possible way to make a tile in a 2D game as a speedbooster and how to do so?
    The concept of the game is a ball rolling at an increasing speed, only with a jump mechanic.
    Just having a hard time figuring out how to make the ball roll constantly without increasing in speed before it reaches the "speedbooster tile".

    So to simplify, I need some help with a "Speedbooster tile" and some kind of script or some kind of 2D component to make my character roll without increasing in speed before reaching the speedboost.

    Thanks a lot, any help with be appreciated.
     
  2. JayJennings

    JayJennings

    Joined:
    Jun 24, 2013
    Posts:
    184
    If you're not familiar with RigidBody2D.AddForce() I'd take a look at that:
    https://docs.unity3d.com/ScriptReference/Rigidbody2D.AddForce.html

    You could move a ball using that, although it wouldn't be rolling with physics (not sure what you're going for). A trigger on your speed booster tile could call code that adds to the force with the ForceMode2D=Impulse (see https://docs.unity3d.com/ScriptReference/ForceMode2D.html).

    If you need the ball to be rolling based on the physics of the scene, you'll maybe have to go with a different approach, maybe look at the Joint2D stuff (JointMotor2D, etc.).

    Hope something there points you in the right direction. Good luck.

    Jay