Creare Videogiochi - Game Developer

Versione completa: Unity 3d Aiuto script
Al momento stai visualizzando i contenuti in una versione ridotta. Visualizza la versione completa e formattata.
Ragazzi รจ da tempo che sto cercando di capire come creare un trampolino,che mi faccia saltare in alto il player.."classico no".
sto crendo un gioco sulla base ti penelope con player relative controller(joistik)
e vorrei creare tipo una foglia,che quando ci salto sopra mi fa schizzare in alto.
Qualcuno a qualche spunto..???
grazie

Exorcist

Codice:
var bounce : boolean = false;

var bounceAmount : float = 10;

var Player : Transform;



function OnCollisionEnter (other : Collision) {

    if(other.gameObject.tag == "Player") {

        bounce = true;

    }

}



function Update () {

    if(bounce) {

Player.rigidbody.velocity.y = 0;    Player.rigidbody.AddForce(0,bounceAmount,0,ForceMode.Impulse);

bounce = false;

    }

}

t detects when the 'Player' (defined by you) enters the objects collider (aka hits it) then sends him into the air. Though this may not be the best way to handle it, it will work until someone with more experienced helps you.
grazie mille per il tuo aiuto..
io pero non ho un rigidbody nel player...ho un charcter controller.
Funzionera uguale??
o devo cambiare qualcosa..
purtroppo ora non ho il pc con unity per provare.
Tu che ne pensi??

Exorcist

Non so prova, ma eccoti anche con character control
Codice:
var jumpSpeed = 35;
var controller;
var gravity = 20.00;
var isJumping: boolean = false;
var Jump : boolean = false;
private var moveDirection : Vector3 = Vector3.zero;

function Update()
    {
    var controller : CharacterController = GetComponent(CharacterController);
    if (controller.isGrounded)
    {
    isJumping = false;
    }
    if (Jump)
    {
    isJumping = true;
    }
    if (isJumping)
    {
    Jump = false;
    controller.Move(moveDirection * Time.deltaTime);
    }
    moveDirection.y -= gravity * Time.deltaTime;
}
function OnControllerColliderHit(hit:ControllerColliderHit) {

    if (hit.gameObject.tag == "Bounce")
        {
        print("afaf");
       Jump = true;
        moveDirection.y = jumpSpeed;
    }
}
ti ringrazio...credo che andra benone...
ObbligatoBig Grin

Exorcist

Di NiEnTe.
E' buona fortuna per il tuo progetto.