ID:1515274
 
Code:
var/obj/e=new
e.icon='excavator.dmi'
e.icon_state="open"
e.pixel_x=-64
e.mouse_opacity=0
e.loc=locate(src.x,src.y,src.z)
spawn(10)
animate(e,pixel_y=500,time=10)
spawn(10)
animate(e,pixel_y=-64,time=10)


Problem description:
I have tried to get this code to work the way I want it but, it is driving me up the wall. What I want to happen is.. I want the excavator icon to move up 500 pixels, smoothly. Then after roughly, 1 second come back down to its original place again, smoothly. Instead of a smooth transition I am getting some really weird movements.



The shovel is where the excavator icon should be stopping.

I feel like I am just doing something obviously wrong but I can't figure it out.

Did you look up animate() in the DM Reference? It explains pretty clearly how to chain animate()s together.

animate proc:
If the Object argument is left out, a new animation step will be created for the last object that was animated.

You don't need those spawn()s, basically, and leave out the e on the secondary calls to animate().
Well I know that... basically in that part I was testing out different options.
animate(e,pixel_y=500,time=10)


I tried this alone and it is still acting awkward.
Why dont you set the e.pixel_y=500 and then just do animate(e,pixel_y=0,time=10).

edit: nvm I see you want it to go up and then down.
var/obj/e=new
e.icon='excavator.dmi'
e.icon_state="open"
e.loc=locate(src.x,src.y,src.z)
e.pixel_x=-64
e.pixel_y=500
e.mouse_opacity=0
animate(e,pixel_y=0,time=10)
spawn(10)
del(e)




So here is what this does. The reason this is confusing me is because the icon should be 500 pixels higher, and then move 500 pixel down. Should it not? Again, the shovel should where the icon finishes moving.
It is doing what you want it's just the top of the icon itself which is the string of the excavator, is actually stopping where you want it. So just adjust the pixels a bit until you get the results you want.
I ended up guessing around values until it looked right but then when I tried to make it scale back up.. it started the process all over again. I have now abandoned the idea of using animate() until I fully understand it.

Fix:
I simply made a proc that does what I thought animate() would do and move the pixel_y down a set amount and then return in the direction it came from.
I am not quite sure what you mean by it not working, doing it like this should probably do what you described,
var/obj/e=new/obj{icon='excavator.dmi';icon_state="open";pixel_x=-64;pixel_y=500;e.mouse_opacity=0}(locate(x,y,z)) //Creating the object with the variables you used.
sleep(10) //Sleep a second before execution
animate(e,pixel_y=0,time=10) //Animate the object e for one second and move pixel_y down to 0.
sleep(20) //Wait for the duration of the animation plus one extra second.
animate(e,pixel_y=initial(e.pixel_y),time=10) //Start a new animation where the object e returns to the initial pixel_y position.
sleep(10) //Wait for the duration of the animation
del(e) //Delete the object e.
its not that animate() wasn't working. I couldn't code it the way I wanted and the way I was trying was not working.


This is what I was trying to do, as I said in my last post I worked around it.
Using just pixel_y seems to be more suited for this than animate is anyways. Also you are not supposed to use sleep() in between multiple animate()'s. The time it takes to animate doesn't correspond the same as the normal tick_lag does. Plus since it won't move on till the animation is finished, you wouldn't need sleep() anyways. Unless you wanted to wait another 10 ticks.

Though, I don't understand why you weren't animating it to pixel_y=-500? Then setting it back to 0. You probably already tried this, and I don't know enough about animate() to see what's wrong with that sorry.
In response to Bakasensei
Oh boy.
Its a long story, Baka. The short version.. I tried the way you had suggested first, that is how I thought it would work, but instead it would jump down like 300 pixels and the smoothly move down. The second code[the one up top] was me trying to see how animate was working. The animate to pixel 500 takes place right at the beginning of that gif, but as you can see its instantly out of the frame and then falls down farther than the point intended.

I like the way I have it setup now better than animate, easier to read and easier to edit smaller things in later.
I noticed some weird happenings too with animate after the last update release for byond...

obj/speech_bubble/New(newloc, msg)
icon = 'bubble.dmi'

var/obj/O = new
O.maptext = msg
O.maptext_width = width
O.maptext_height = height
overlays = O

// start below final position and jump into place
pixel_z = -100
alpha = 0
animate(src, pixel_z = 0, alpha = 255, time = 10, easing = ELASTIC_EASING)


That above code used as an example to explain elastic easing in the help file doesn't work as it should anymore either. It seems to continue moving the object upwards for the duration of time then afterwards it simply auto relocates the object to pixel_z = 0