# playMaker

### Author Topic: speed changing from float interpolation  (Read 357 times)

#### santelia

• Jr. Member
• Posts: 78
##### speed changing from float interpolation
« on: July 08, 2012, 07:11:08 AM »
It would be nice if we could set speed using the output of a "float interpolate" action, with an "every frame" option. I mean in the same way as we already can set a scale using a value resulting from "vector3 interpolate".
As it happens in my case, it could be useful for managing movements of objects that need to accelerate, then move constantly toward a certain point, then brake when arrived at a certain distance. Or simply accelerate/brake.
Is there any workaround for that? I mean yet available?

#### Alex Chouls

• Hero Member
• Posts: 1674
##### Re: speed changing from float interpolation
« Reply #1 on: July 08, 2012, 12:20:07 PM »
Have you tried Move Towards while controlling the Max Speed?

You can set Max Speed to a float variable and change it over time to clamp the speed at which the game object moves.

You can also combine lower level actions:

Vector3 Subtract to get a vector towards a target.
Vector3 Clamp Magnitude to clamp the speed.
Translate to apply the movement vector to a GameObject.

This gives you more control if you need other steps in there...

#### santelia

• Jr. Member
• Posts: 78
##### Re: speed changing from float interpolation
« Reply #2 on: July 09, 2012, 07:04:21 AM »
Thank you Alex.
Following your suggestion, I'm trying to sort things out but I have to admit it seems not so obvious.
So, how would you structure the flow if your goal was as follows.
You've got a position (vector3) where your object have to move to.
You need:
1) accelerate for the first 5 seconds seconds and travel (along a straight path) for not more than N distance ranging from 0 to F max speed
THEN
2) proceed at at F fixed speed to a certain position
THEN
3) brake from F to 0 in the remaining N last distance.
?

#### jeanfabre

• 1.2 Beta
• Hero Member
• Posts: 3727
##### Re: speed changing from float interpolation
« Reply #3 on: July 10, 2012, 01:02:50 AM »
Hi,

Have you though about using a pathfinding system? this kind of behaviour are the job of such framework. and you will gain a lot of potential useful feature as your game will evolve, for example obstacle avoidance, retargeting.

Do you have unity pro or indie?

Is your target moving or fixed?

to do that manually:

the way you describe it is very much the way it's going to be design in the fsm. So you have three states, "accelerate", "cruise", "decelerate". I would however inject a state before that that turn the ship towards its target. so

"TURN"
"ACCELERATE"
"CRUISE"
"DECELERATE"

upon a global transition "MOVE BOAT" or something, get the direction of the boat etc etc and enter the state "ACCELERATE", in that state you move your boat at an increasing speed, in the same state you record the distance it traveled, and it move to the next state "CRUISE" once it reached a certain distance, and so on.

to mimic acceleration and deceleration, use the "translate" action and increase or decrease the value you inject in there using "float interpolate".
To detect the travelled distance, you can check the distance remaining towards the target or the distanced travelled from the start point using "get distance" action.

be aware that some initial check up would be required, if for example your target is closer than the acceleration and deceleration range, then you will have to accomodate for this for a realistic behaviour.

All in all, this kind of behaviour is quite a complex task to tackle, so be patient with this.

bye,

Jean

#### santelia

• Jr. Member
• Posts: 78
##### Re: speed changing from float interpolation
« Reply #4 on: July 13, 2012, 05:45:37 AM »
No, at this stage of the project (actually two projects: one rts game and one sci-fi rpg), I'm using indie version. Since Unity v.4 is on the way to be released, maybe then I'll buy Pro.
As far as pathfinding systems are concerned, which one would you suggest based on flexibility and performance?
At this point of the development, nevertheless, I believe we've already done some steps forward with a specific project-taylored set of solutions, including some very specific new actions, and I wouldn't be very happy to restart from scratch just to integrate a commercial pathfinding if not compelled to.

#### jeanfabre

• 1.2 Beta
• Hero Member
• Posts: 3727
##### Re: speed changing from float interpolation
« Reply #5 on: July 13, 2012, 06:06:38 AM »
Hi,

I haven't really played with pathfinding framework other then the unity pro own system, so can't really say.

Now, from my experience, I found that sometimes picking the right solution even if it means rewriting is often mandatory in the long run... it's alway a difficult choice, so gather as much information as you can on forums as what solution would best suit your needs.

Meanwhile, have you had a chance to try what I explained?

bye,

Jean

#### santelia

• Jr. Member
• Posts: 78
##### Re: speed changing from float interpolation
« Reply #6 on: July 13, 2012, 06:31:15 AM »
Yes Jean, built a complete set of states to be used in many situations of movements, all referring to custom variables. And since many objects to be moved are boats or ships, we added some custom actions (using Bezier math too) to calculate route and apply various rudder angles depending on distance, speed, type of boat, situations, etc. Ops, and thank you for all those trigo actions, of course.
« Last Edit: July 13, 2012, 09:41:16 AM by santelia »