Passing Arguments To Functions

Hi, I’m trying to create a simple function to tween entities that I pass in to a position that I also pass in. However my code isn’t working and I’m sure its something obvious. I couldn’t find any example of doing this online.

The code looks like this:

PlayAnim.prototype.slide_in_entity = function(entity, to_position) {
    entity.tween(entity.getLocalPosition().to(to_position), 0.5, pc.SineOut).start();
};

and I call the function like this (in this case to an entity called lower_button_group):
this.slide_in_entity(this.lower_button_group,new pc.Vec3(0, 0, 0));

Anyone help with this one?
Thanks

Hi @Grimmy

PlayAnim.prototype.slide_in_entity = function(entity, to_position) {
     entity.tween(entity.getLocalPosition())
          .to(to_position), 0.5, pc.SineOut)
          .start();
};

At first glance it looks like there was a missing close parenthesis closing your tween() function before moving on to the .to() portion. Are you getting errors in your console?

Yeah, but if I put the extra parenthesis I get this error.
image

How does the function know what the type of each argument is? (entity, Vector) Am I supposed to declare this somewhere?

@Grimmy,

Sorry about that. I missed that the paranthesis after to_position needs to come out:

PlayAnim.prototype.slide_in_entity = function(entity, to_position) {
     entity.tween(entity.getLocalPosition())
          .to(to_position, 0.5, pc.SineOut)
          .start();
};
2 Likes

Perfect. Thanks you so much. Works perfectly now :slight_smile: