- Home /
Animation reverse
Hey there!. Im having problem with my script. what the script does is that it displays a icon when you are aiming on the " door " and that works just fine and opening also. the thing Im trying to add to the script that gives me problem is animation reverse for closing the door. it gives me a error at line 41 saying that " = " is incorrect. isnt that how it suppose to be ?
function Update()
{
var hit : RaycastHit;
//check if we're colliding
if(Physics.Raycast(transform.position, transform.forward, hit, rayCastLength))
{
showSymbol = true;
//with a door
if(hit.collider.gameObject.tag == "doorl")
{
if(Input.GetKeyDown("e"))
{
//open the door!
hit.collider.gameObject.animation.Play("doorleft");
}
}
else
{
{
hit.collider.gameObject.animation.Play("doorleft").speed=-1f;
}
}
//Copy and paste the code above and rename the door animation and that's it! You now have another door in your game!
}
else
{
showSymbol = false;
}
}
}
}
}
Answer by deltamish · Jun 23, 2013 at 06:15 AM
Hi the problem is very simple all you have to do is change from
CHANGE FROM
{
hit.collider.gameObject.animation.Play("doorleft").speed=-1f;
}
the reason this line doesnt work is because animation.Play(); is call only function
CHANGE TO
{
hit.collider.gameObject.animation["doorleft"].time = hit.collider.gameObject.animation["doorleft"].length;
hit.collider.gameObject.animation["doorleft"].speed = -1;///This lets you change speed of the animation
hit.collider.gameObject.animation.Play("doorleft");
}
Your Script Rewritten
var dooropen:boolean = false;
function Update(){
var hit:RaycastHit;
if(Physics.Raycast(transform.position, transform.forward,hit, rayCastLength)){
showSymbol = true;
if(hit.collider.gameObject.tag == "doorl"){
if(Input.GetKeyDown(KeyCode.E)){
dooropen = true;
hit.collider.gameObject.animation.Play("doorleft");
}else{
if(dooropen){
hit.collider.gameObject.animation["doorleft"].time = hit.collider.gameObject.animation["doorleft"].length;
hit.collider.gameObject.animation["doorleft"].speed = -1;///This lets you change speed of the animation
hit.collider.gameObject.animation.Play("doorleft");
dooropen = false;
}
}
}else{
showSymbol = false;
}
}
}
Thanks Deltamish I tried it out and it still gives me the same error :( it says ( expecting token : ,found "=" ) on line 42. I know that it means that I need to change = symbol to : but that wont work eather I have also looked in to other reverse animaition scripts and mostly all of them uses " = ", why cant I ? : (
Hi @felixfors Sorry for the late reply i dont know why you are getting this error Are you sure you typed the codes correctly and please post the full error and the script
Hey @deltamish Im still struggeling with this problem and Im glad for all posible help I can get. Full script:
function Update() { var hit : RaycastHit;
//check if we're colliding
if(Physics.Raycast(transform.position, transform.forward, hit, rayCastLength))
{
showSymbol = true;
//with a door
if(hit.collider.gameObject.tag == "doorl")
{
if(Input.Get$$anonymous$$eyDown("e"))
{
//open the door!
hit.collider.gameObject.animation.Play("doorleft");
}
}
else
{
{
hit.collider.gameObject.animation["doorleft"].speed = -1;///This lets you change speed of the animation
hit.collider.gameObject.animation.Play("doorleft");
}
//Copy and paste the code above and rename the door animation and that's it! You now have another door in your game!
}
else
{
showSymbol = false;
}
}
} } }
Error: BCE0044: expecting :, found "=". at line 25.
why are there two flower brackets here
else
{
{///This one here shouldnt belong i think
hit.collider.gameObject.animation["doorleft"].speed = -1;///This lets you change speed of the animation
hit.collider.gameObject.animation.Play("doorleft");
}
and here
if(Input.Get$$anonymous$$eyDown("e"))
{
//open the door!
hit.collider.gameObject.animation.Play("doorleft");
}
}
else
{
I have rewriiten your complete script try it
Hey thanks! it seams to have changed something to the better, but It still not 100% working, the animation plays reversed now but when ever I walk up close to the door without pressing any key to trigger the animation it just goes off playing by itself but like a ping pong effect" close and open" repeatedly tils I step away from the door. why? I want the animation only to be played when $$anonymous$$ey E is pushed down :(
Your answer
Follow this Question
Related Questions
Flip back a frame 1 Answer
How to stop a FBX animation mid-way and then reverse it from that point? 1 Answer
Help making an animated door (c#) 2 Answers
Play animation backwards 1 Answer
[Solved] Reverse animation 1 Answer