FORUMS: list search recent posts

Horse Race Game

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Dave Kaiser
Horse Race Game
on Apr 17, 2013 at 8:29:18 pm

I'm VERY new to Expressions (read: started today). I'm creating a :20 second video of a horse race game that will be manually adjusted each week with a new ending position for each horse. I'd like to figure out an expression that will smoothly vary the speed of each horse's movement every 1 second, from right to left, without ever moving "backwards". The speeds must differ enough so that the lead horse changes every so often so it's not obvious which horse will win.

I tried simply using the wiggler on position, but the horses end up moving forwards and backwards as they "race".

Return to posts index

Xavier Gomez
Re: Horse Race Game
on Apr 18, 2013 at 5:56:57 pm

you can use wiggle, but on the speed, not the position itself, then integrate the speed. To get more precise, you should tell if your problem is 1D (horses moving in straight lines) or 2D (horses running in "circles"). It's not quite the same since for 2D closed path you will want to wiggle only in one direction (tangent to the movement).

Return to posts index

Dave Kaiser
Re: Horse Race Game
on Apr 18, 2013 at 6:11:17 pm

The problem is 1D (horses running in straight line, right to left).

Can you explain how to apply a wiggle to "speed". Since that is not a property listed on the horse layer, I can't just pick whip to "speed".

Return to posts index

Xavier Gomez
Re: Horse Race Game
on Apr 19, 2013 at 11:44:41 am

I can help for one aspect (horse not moving backwards!) but some other aspects of your project are kinda more difficult:
- to reproduce realistic behaviour of a horse is hard with a simple wiggle.
- also to obtain different race results in the same settings require some knowledge in seedRandom which i havent...

For what i can help,you can procede this way:
1) Create an ideal horse (without wiggle) that will give the generic behaviour of your horses.
Just create a Null Object (rename it MASTER HORSE), and animate it smoothly from start to end (with 2 or more keyframes).
Adjust temporal tangents so that it starts with 0 speed and ends at max speed.
On that null, apply a slider control (Effects > Options for Expressions > Slider Control), rename it master speed), alt+Click the stopwatch to activate the expression field and enter this expression:


Instead of animating the null and taking its speed, you can also directly enter an explicit expression for the Master Speed slider:

maxSpeed = 75;
t0 = 2; // kick time
T = 2;

t = time - t0;
(t<0) ? 0 : maxSpeed * (1 - Math.exp(-t/T))

2) Take one horse layer, add a slider control, name it Horse Speed, and use this expression:
f = 1; // wiggle frequency
w = 10; // wiggle amount
t0 = 2; //kicktime

if (time < t0) 0 else{
x = wiggle(f,w) + thisComp.layer("MASTER HORSE").effect("master speed")("Slider");
(x > 0) ? x : 0;

This gives each horse its individual speed. Sort of naive though and it is the part that should be improved.

3) Then for the position property of the horse, set the value to the start position and don't animate it (with keyframes). For the expression, enter this:

x = 0;
vel = effect("Horse Speed")("Slider");
dt = thisComp.frameDuration;
t=- dt;
numFrames = timeToFrames(time);

for (var f = 0; f<=numFrames; f++){
x += vel.valueAtTime(t)*dt;
t += dt;

value - x*[1,0];

Return to posts index

Dave Kaiser
Re: Horse Race Game
on Apr 19, 2013 at 3:27:28 pm

Wow. Thanks! A few questions:

1) What is the "kicktime" control exactly?
2) How would I control the final ending place for each horse in the race?

Here is an example of what I'm trying to accomplish (only this I set up manually with position keyframes):

Return to posts index

Xavier Gomez
Re: Horse Race Game
on Apr 19, 2013 at 5:44:27 pm

if you want the horses to stand still for a couple of seconds before the start of the race, set kickTime = 2 (assuming that your comp start time is 0). This is only useful if you use the second method i give you to get the "Master speed". If you animate by hand the "MASTER" HORSE you dont need this.

For the remaining of the question i dont understand. I thought it was a random race with random results...

Also the last lines of the last expresion i gave you should be replaced by
for (var f = 0; f<=numFrames; f++){
x += vel.valueAtTime(t);
t += dt; }
value - x*dt*[1,0];

It does the same, but should be significantly faster.

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved