Spawns

Hello Unity Community!

I need you help for 2 problems that i have and i’m sure that they are pretty simple to solve but i kind of fail.

Problem 1)
I have a usable car in which you can enter and drive around. When going into the vehicle, the player object get teleported into the vehicle and then gets a child of the car object (so that the player model follows the car). Now my problem:
How to leave the car so that the player gets spawned @ one of the car doors? Of course i could add a gameobject to every door and get its position but the must be another better way right? (calculating the teleportation positions considering car rotation and so on, for example going from the cars pivot point/center)

Problem 2)
Lets say i have a button ingame, and if i press that button a new car object spawns to a specific location even if the car object doesn’t exist yet in the scene. How to do that?

Thanks for your help guys!

  1. Look at transform script component.

car.transform.position + car.transform.right * 0.5f // or any combo of offsets to get door position. Can even use player.transform.forward = car.transform.right to make sure the player is facing the right way when you pop them out of the car too.

  1. Unity - Manual: Prefabs and then go though all of the sections in the basic Unity scripting Overview: Unity - Scripting API: this will answer your second question, and probably the next 4 or 5 questions you might have too.

edit just found my own mistake -.- alright thanks a lot problem solved