- Home /
exiting a car at the same spot every time??
Ok, so I'm having a small issue with my car that apparently no one else has run into. If I get out of my car while it's facing in its original direction, I exit riiiight beside the driver's side door. Unfortunately, however, if I turn the car around, I exit right near the back right-hand side of the car. If I face my car to the right of it's original position, I exit by the back of the car. Get the idea? In the code that I'm about to include, I was wondering if someone could show me what I'd need to throw in there so that I always exit with my character standing by the driver's side door, regardless of the orientation of the car. Thanks in advance!
else if (inVehicle) {
rigidbody.isKinematic = true;
inVehicle = false;
nextToVehicle = false;
VehicleCam.camera.enabled = false;
Player = Instantiate(GameObject.Find("Clone"), transform.position + new Vector3(-2, 0, 0), transform.rotation) as GameObject;
Player.name = "Player";
Player.tag = "Player";
CharacterMotor PlayerScript = Player.GetComponent<CharacterMotor>();
PlayerScript.canControl = true;
miniMapScript.playerTransform = Player.transform;
followScript.target = Player.transform;
Answer by Rennat · Aug 15, 2011 at 09:24 PM
...
// doesn't work
// offsetting by global coordinates the same direction every time
Vector3 exitPosition = transform.position + new Vector3(-2, 0, 0);
// does work
// offset taking transform rotation into account
Vector3 exitPosition = transform.position + transform.right * -2;
Player = Instantiate(GameObject.Find("Clone"), exitPosition, transform.rotation) as GameObject;
...
So I'm a bit confused as to how this would work, mostly because of the fact that your solution is in javascript, and, unfortunately, my code is in C#. Any chance you could translate it? That would be a HUGE help. Thanks!
You're right it is C#, I wasn't paying attention. Editing my answer.
You are my hero. I don't know why I couldn't figure this out, but you've seriously made my day.
Hi @$$anonymous$$ulahan, would you "thumbs up" this answer? I'm kind of a $$anonymous$$arma whore. :)
I would love to, but for some reason it says I don't have permission :/ Sorry Edgar Allen Bro.
Answer by illwunn · Aug 15, 2011 at 06:59 PM
Maybe add an empty game object that is a child of the vehicle and use it as a spawn point, position it by the drivers side door and use it's position as the reference position in your instantiate
That won't work - I have way too many cars in this game for me to sit around and add invisible boxes to all of 'em. Just a huge pain in the ass. I feel like something along the lines of a vector3(transform.eulerangles.x - 2, etc, etc) would work, but for some reason, it's not. Any ideas?
ah i c, well i see you are using the world position in your instantiate, have you considered using the local position of your vehicle? try using transform.localposition
unfortunately, that doesn't work - it does the same thing as the normal world position. I spawn at the same spot, regardless of how I orient the vehicle.
Your answer
Follow this Question
Related Questions
Void loop? 2 Answers
Brake Light Button 1 Answer
Make a noise when i crash into something 1 Answer