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. Dismiss Notice

Load and place prefab at position a distance from target

Discussion in 'Scripting' started by NDSno1, Oct 13, 2016.

  1. NDSno1

    NDSno1

    Joined:
    Dec 20, 2014
    Posts:
    223
    Hi,
    I'm trying to load a car prefab and would like to place it at position so that the collider of that prefab is in contact with the collider trigger at the starting line and a distance away from the AI car next to the player car. It's a drag race by the way, so only 2 cars on the road. The messes and colliders on each car are different due to the different in size, so the center point or pivot point will not always be a reliable pivot
    I'm thinking about making a animation clip rather than just throwing prefabs in, by making 2 cars move forward until they both hit the trigger at starting line, then start the count down. However, I still have no idea how to make sure the cars move to the trigger in an exact time duration, because I'm using wheel colliders to move the cars, and each car has different value that will affect the speed if it is given a fixed motorTorque value.

    Also, just an extra question, is there a way that I can control radial fill of Texture2D as I could with UI Image? I'm trying to make a ring that will gradually fill up and follow the needle on the tachometer, and the tachometer and needles are Texture2D so that I can rotate the Texture2D needle with RotateAroundPivot.

    I'm sorry for asking so many questions. Thank you very much.
     
  2. NDSno1

    NDSno1

    Joined:
    Dec 20, 2014
    Posts:
    223
    Bump. Anyone got any idea?
     
  3. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,950
    Just determine the start location or the offset and store in the prefab as a value. Or just put an empty transform in the prefab as locator that indicates where the "front" is. Use that to calculate the offset.
     
    NDSno1 and Kiwasi like this.
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Yes. There are inspector settings on the image that do exactly that.
     
    NDSno1 likes this.
  5. NDSno1

    NDSno1

    Joined:
    Dec 20, 2014
    Posts:
    223
    Thanks for the reply, but what I'm interested in is to modify to radial fill of texture2D at runtime with script, not with image
     
  6. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,950
    Kiwasi likes this.
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    (Almost) Everything that can be configured in the inspector can also be configured at runtime via a script. At the time I couldn't remember the name of the property and didn't have the time to look it up. Follow the link zombiegorilla put up for the documentation.