Search Unity

My animations won't stop.

Discussion in 'Scripting' started by VRaptorX, Sep 12, 2012.

  1. VRaptorX

    VRaptorX

    Joined:
    Sep 27, 2011
    Posts:
    108
    I'm trying to make a crane game and using rotation failed horribly with clipping so I'm not using pre-canned animations. My plan is that upon contact with a prize, the animation stops in place. That way you never quite get a full grip on the item you are trying to carry.

    Unfortunately the animations do not stop. It goes to where it has to go but nothing else. It doesn't even say the debug line for when it stops. The colliders don;t seem to understand that they connected, but I can grip the objects and lift them, so they ARE colliding.

    PHP:
    #pragma strict

    var animatePhysics boolean;
    var 
    int;

    function 
    Start () {
        
    animation.Play ("Open");
        
    animation.wrapMode WrapMode.Clamp;
        
    0;
    }

    function 
    Update (){
        if (
    Input.GetKeyDown ("space")) {
            
    playanimation();
        }
    }

    function 
    playanimation(){
        
    ++;
            if (
    == 1){
                
    animation.Play ("Close");
            } else if (
    == 0){
                
    animation.Play ("Open");
            }
    }

    function 
    OnCollisionEnter (col Collision){
        if(
    col.gameObject.tag == "Prize"){
            
    animation.Stop();
            
    Debug.Log("should stop");
        }
        
        if(
    col.gameObject.tag == "Release"){
            
    animation.Play ("Open");
            
    Debug.Log("should open");
        }
    }
    Any idea why this is happening?
     
  2. FlinixStudios

    FlinixStudios

    Joined:
    Jul 20, 2012
    Posts:
    13
    Because you did the collision wrong if I am correct. Try this instead of animation.play . Animation.play (Open) Animation.close on animation.player. enjoy I may have put one error just put the sl in and it should fix it.
     
  3. VRaptorX

    VRaptorX

    Joined:
    Sep 27, 2011
    Posts:
    108
    I don't understand what you mean.
     
  4. kingcharizard

    kingcharizard

    Joined:
    Jun 30, 2011
    Posts:
    1,137
    are your game objects tagged?
     
  5. Joppel

    Joppel

    Joined:
    Aug 4, 2012
    Posts:
    34
    He means you need to use the right command.
    animation.play does nothing.
    Animation.play is what you're after.

    capitalised first letters in functions and classes, small in variables.
     
  6. Loius

    Loius

    Joined:
    Aug 16, 2012
    Posts:
    546
    Animation doesn't have a "play" variable.

    Do you have non-kinematic rigidbodies attached to your prizes, and kinematics attached to your claws? That should set you up to register collisions.

    Try debug.logging in OnCollisionEnter, at the very start, to see if the claw connects at all. It's possible the tags are incorrect, or one or more objects are mis-tagged.
     
  7. VRaptorX

    VRaptorX

    Joined:
    Sep 27, 2011
    Posts:
    108
    Yeah, I have non-kinematic bodies. (why should the claw be kinematic? If I do that it just goes through everything. The prizes are tagged and layered Prize. I don't have a release cube yet.

    But yeah, I debugged on collision. heck, I made it so it it destroys itself if it touches anything. It touches stuff. It stops. But it does not destroy. I also tried a print statement and it does nothing as well. It connects but doesn't register that it connects.
     
  8. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Add a breakpoint at on collision and see what game object equals in the debugger.
     
    Last edited: Sep 17, 2012
  9. VRaptorX

    VRaptorX

    Joined:
    Sep 27, 2011
    Posts:
    108

    I have no idea what a break point is. This is my current code.

    PHP:
    #pragma strict

    var animatePhysics boolean;
    var 
    int;
    var 
    speed float;

    function 
    Start () {
        
    animation.Play ("Open");
        
    animation["Open"].speed 1.0;
        
    animation.wrapMode WrapMode.Clamp;
        
    0;
    }

    function 
    Update (){
        if (
    Input.GetMouseButtonDown (0)) {
            
    playanimation();
        }
    }

    function 
    playanimation(){
        
    ++;
            if (
    == 1){
                
    animation.Play ("Close");
                
    animation["Close"].speed 1.0;
            } else if (
    == 0){
                
    animation.Play ("Open");
                
    animation["Open"].speed 1.0;
            }
    }

    function 
    OnCollisionEnter (){
        
    //if(col.gameObject.tag == "Prize"){
            
    animation["Close"].speed 0.0;
            
    Debug.Log("should stop");
    //    }
        
    }
    I'm just trying to pause an animation on the frame it makes contact.

    I've tried capitalizing the A but it keeps giving me errors saying Animation is not a real thing. Theoretically, changing the animation speed to zero should and then switch it back to 1 each click should work. But it doesn't.