Help with functions and velocity

Currently working on a football project, but I’m having trouble. I want the function be ran multiple times simultaneously, when it makes the football player NPC follow a specific route. Routes are formatted like this in an array:

[
[duration, Yvelocity], <—  wait for duration, than set velocity
[duration, Yvelocity]
]

The way the function is supposed to work is the NPC follows a specific route, but sometimes the velocity will act erratically. And only one route can run at a time it seems.

Code

Positions

RESULT:
IMG_2531

@richard or anyone else’s help is greatly appreciated :grin:.

4 Likes

THE LEGEND IS BACK!!! I HAD THOUGHT WE LOST YOU. BUT YOUR BACK!!!

(sorry this is very unhelpful)

3 Likes

Could you share the link? I cant think / properly solve problems without way more info than you’d think is necessary. Well I guess my brain works like that.

Anyways link plz?

2 Likes

Great mechanic, @Unique !

You’re running into an issue with global variables. Instead of using your variables routeDuration and routeVelocity, access the array directly.

Take a look here:

Holler if you still need help.

3 Likes

A more detailed explanation of why the global variables posed a problem:

Open for more detail

The values for the global variables are set before the pause runs. After the pause finishes, those global variables may have been replaced with different values with a separate call to run route.

You could try moving the block that sets the value of routeVelocity after the pause block, and that might work just fine. Still, you risk this same kind of clash when the function is called multiple times.

The function holds on to a reference to the array until the call has finished. (It’s a parameter, so it’s a local variable specific to the function call.) So, when calling this function multiple times in parallel, accessing the values of the array directly (in other words, accessing the parameter) is the safest way to go.

3 Likes

Awesome, thanks @AlexK :grin:!
Switched from using sprite velocity to angles, works perfectly.

Finished Mechanic Code

3 Likes

I can’t wait to see where you take this, @Unique ! It looks great!

3 Likes

Only for a little while, but yes!

This has been a side-project of mine for a while, so I’ve been working on it incrementally. But it’s coming together nicely, so basically, more posts are coming soon.

1 Like

yo is that techmo bowl