- Home /
spawn player near driven car.
I want to know how can I spawn my player near my car. I enter the car and drive to the other side of the map. I then exit the vehicle and I spawn where I got in the vehicle.
How can I spawn the player from next to my car and vice versa.
Script:
 using UnityEngine;
 using System.Collections;
 
 public class ChangeCameraMoreSimple : MonoBehaviour
 public class CharacterController : MonoBehaviour // this is where the problem is.
 
 {
 public GameObject carCamera;
 public GameObject playerCamera;
 public GameObject Car;
 public GameObject Player;
 
 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
 if (Input.GetKey(KeyCode.E))
 {
 carCamera.active = true;
 playerCamera.active = false;
 
 
 Player.active = false;
 Car.active = true;
 }
 if (Input.GetKey(KeyCode.R))
 {
 playerCamera.active = true;
 carCamera.active = false;
 
 Player.active = true;
 Car.active = true;
 GetComponent(CharacterController).enabled = true;
 
 }
 }
 }
You don't include code here, so I'm just guessing, but an easy way to have the player spawn near the car is to make the spawn point a child of the card.
You need to show us the code and explain more. There is not enough information here to give you even a guess for a multiple car situation. Are there more than one driver/player? How is the player mapped to the car? How do you tell which care is the current one? Can the player spawn to any car or just to a specific car?
how would i spawn the character when i get outside my car as i want the character to spawn next to the car i was driving.
I'm still not sure what you are asking, and I don't see the spawn code here. You could do something like:
 Player.transform.position = Car.transform.position + Car.transform.right * some_distance;
This will place the player 'some_distance' to the right side of the car.
Your answer
 
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Random spawnpoint where only one prefab can spawn! 1 Answer
Clients moves to NetworkSpawnPositions at start 0 Answers
Spawn single floor tile at mouse position 1 Answer
JS Enter Exit with NetworkPlayer 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                