xxxxxxxxxx
37
/***********************************************
Simple path following (steering)
Daniel Shiffman up to 12' into the video
https://www.youtube.com/watch?v=rlZYT-uvmGQ
For a more complex path following either I do it as an exercise (see explainations in the video from 12' to 15'30'').
The solution made by Daniel Shiffman is here : https://editor.p5js.org/codingtrain/sketches/2FFzvxwVt
Voir aussi 5.2 Seeking a target https://www.youtube.com/watch?v=p1Ws1ZhG36g
***********************************************/
let vehicle ;
function setup() {
createCanvas(800, 400);
vehicle = new Vehicle( 100, 100 ) ;
vehicle.vel.x = 2 ;
path = new Path( 0, height/2, width, height/2 ) ;
}
function draw() {
background(70);
path.end.y = mouseY ;
let force = vehicle.follow( path) ;
vehicle.applyForce( force ) ;
vehicle.edges() ;
vehicle.update() ;
vehicle.show() ;
path.show() ;
}