So hard to describe in the title but basically when I eject from an airplane and its spinning off axis.
I think the problem is im spawning to a GameObject Child of the plane in Local space so when i appear as the plane is in a roll, my character spawns upside down or whatever LocalRotation it is currently in and then I land on my side or head and stuck.
exitPoint.parent = jet.transform;
exitPoint.transform.localPosition = Vector3(-2.5,0,0);
So exitPosition is the GameObject my player reappears at when he gets out
(-2.5) is just offset enough to clear the plane and no collision issues.
Im guessing it needs to be in World.Rotation or something along those lines.
Newbie here pulling his hair out, self taught.
Thanks for reading and happy designing!
You question is hard to understand. I think you are asking to have your character spawn upright even when the plane is an an odd angle, and that currently your character is taking his rotation from the plane. An easy solution is to use Quaternion.identity or Quaternion.Euler(someval,someval,someval) in the Instantiate(). These set the rotation to world coordinates, so the character will always be at the same rotation no matter what the orientation of the plane.
Another solution that might work better is to spawn the character at the planes rotation and then rotate the character so his head is facing up. So after your current spawn you can do:
transform.up = Vector3.up;
Here is an alternate:
transform.rotation = Quaternion.FromToRotation(transform.up, vector3.up) * transform.rotation;
I would recommend "robertbu "'s answer, and set your rotation to a global value (identity) instead of the relative rotation (relative to the plane). When you instantiate, you are probably doing somehting similar to the following:
Instantiate(playerPrefab, plane.posiiton, plane.rotation);
Instead, do this:
Instantiate(playerPrefab, plane.position, Quaternion.identity);
This makes the player get instantiated with a rotation that is upright.
I would suggest using a lerp function to make the player slowly rotate to this value (to make it more realistic and not as snappy). I would also add some kind of offset from the plane for when you instantiate the player (or your player head could get stuck in the plane form being upright when the plane is at an angle or you are slightly inside of a wing or something). If you don’t, you could get odd results.
So Im still having trouble with this, Im new and this flight script is far beyond the couple books I picked up on Java so bear with me.
Here is the whole enter/ exit code. It works, I can get in and out, change cameras from the character to the Jet, and have Flight controls. Im just having issues when I eject or press R/“Exit”
Im sure you guys gave me the right answers above, I just wasnt having much luck implementing them. Got some crazy results on some but Im that was me not your code.
I hate to ask for so much help but everything I do either doesnt do anything or sends my character out to space.
Thanks for everyones help and patience. Its Christmas after all LOL. Happy Holidays.
function Start(){
CarCamera.enabled = false;
}
function Update(){
if (Input.GetButtonUp("Enter")&& isPlayerVisible){
// make player invisible and still standing
player.gameObject.SetActiveRecursively(false);
player.gameObject.active = false;
// parent player to Exit Point. This is a trigger box
player.parent = exitPoint.transform;
player.transform.localPosition = Vector3(-1.5,0,0);
// parent PlayerParent to car
exitPoint.parent = car.transform;
exitPoint.transform.localPosition = Vector3(-0.5,0,0);
// Enable Car as controllabe object. Jet is the Prefab, Flight is the flying Script
GameObject.Find("Jet").GetComponent(Flight).enabled=true;
PlayerCamera.enabled = false;
CarCamera.enabled = true;
}
else
{
if (Input.GetButtonUp("Exit")){
// make character visible again
player.gameObject.SetActiveRecursively(true);
player.gameObject.active = true;
// unparent player from everything
player.transform.parent = null;
// parent Exit Point to door Trigger
exitPoint.parent = doorTriggerLeft.transform;
// disable car as controllable
GameObject.Find("Jet").GetComponent(Flight).enabled=false;
PlayerCamera.enabled = true;
CarCamera.enabled = false;
}
}
}