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

how to calculate the initial position

Discussion in 'Scripting' started by ndikadaniel01, Feb 26, 2018.

  1. ndikadaniel01

    ndikadaniel01

    Joined:
    Oct 18, 2017
    Posts:
    1
    hello, I am currently working on a racing game; I would like that when the car is off or when there is a crash the vehicle will resume its original position. I would like to know if there are functions capable of doing its in unity.......
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    That question is very broad, and the description is very vague. Define what's the "initial" and/or "original" position for you in that context / in your application.

    Yes, of course it's possible.
    It's just that you have to define the behaviour first, then implement it using various API calls so that you achieve the desired behaviour.
     
  3. busterlock

    busterlock

    Joined:
    Sep 26, 2015
    Posts:
    58
    If what you mean by "original position" is literally the place it was when the race started, you could achieve that by:
    1) Placing a a collider somewhere under the track that detects in case the player left it
    2) Create an empty object where the "original position" is
    3) Get the transform.position.x, y and z of that empty game object and apply it to car

    Colliders are easy to use, and to set the position you can follow the idea from the next tutorial:

    https://docs.unity3d.com/ScriptReference/Transform-position.html

    I think that pretty much covers it!