enter code hereokay, i have my script for the respawn as the tornado twins showed it. and i added that script to the character prefab that came with the island in unity, and the respawn works, my player goes back to y=200 (thats where i origanlly started) but, i want my player to fall to the ground. can anyone please help me?
my script is:
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
var bullitPrefab : Transform;
private var dead = false;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "fallout")
{
dead = true;
//substract life here
}
}
function FixedUpdate() {
if (grounded) {
// We are grounded, so recalculate movedirection directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
function Update()
{
if(Input.GetButtonDown("Jump"))
{
var bullit = Instantiate(bullitPrefab,
GameObject.Find("spawnPoint").transform.position,
Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 4000);
}
}
function LateUpdate()
{
if(dead)
{
transform.position = Vector3(0,200,-50);
}
}
@script RequireComponent(CharacterController
)
im sorry if someone posted this question already, i couldnt find it.
Most likely the case is that when you first launch the level your character controller is not in fact resting exactly on the ground plane so gravity kicks in and the player drops to the ground. You can check this by viewing the player from the side and check the capsule for the char controller's position.
and to answer your question you can just change the +Y transform position of your respawn location. So if 200 is exactly level with the ground, then just add 50 units or so (0.250.-50) and you should be above the ground.