Code edit (9 edits merged)
Please save this source code
User prompt
the Shortest distance to road calculation does not seem to yield the expected result. if the car is driving on the center of the road the expectation is that the result should be zero
User prompt
in tick, use calculateDistanceToPoint to calculate the shortest distance to any road segment
User prompt
in the game class, add a method that can calculate the distance between a point (the car) and a given line segment (segments)
Code edit (1 edits merged)
Please save this source code
User prompt
for the secound point in distanceToLineSegment use the rotation of the road and height of road to calculate that point
User prompt
In tick use the distanceToLineSegment method to calculate the shortest distance to any segment
User prompt
In tick use the distanceToLineSegment method to calculate distance to the segment at index 0
User prompt
in game, add a method that can calculate the distance between the car and a given line segment based on line (segment) to point (car) math
User prompt
the road segment distance calculation does not seem to work
Code edit (1 edits merged)
Please save this source code
User prompt
In tick, calculate how close the car is to the center line of any road segment
User prompt
make the first road segment created 3000px long
User prompt
make the first road segment created 3000px long
Code edit (1 edits merged)
Please save this source code
User prompt
in tick calculate if the car center is currently inside or outside any of the road segments
User prompt
when destroying a road segment also call self.addRoadSegment
User prompt
only delete road segments that are twice the height of the screen outside the screen
User prompt
delete initialSegment
User prompt
delete initialSegment
Code edit (8 edits merged)
Please save this source code
User prompt
use self.toLocal for segmentGlobalPosition calc
Code edit (1 edits merged)
Please save this source code
User prompt
in tick, calculate if road segments are outside the screen at the bottom
User prompt
use segmentWidth for road width
===================================================================
--- original.js
+++ change.js
@@ -18,9 +18,9 @@
y: vector.x * sinAngle + vector.y * cosAngle
};
};
var carGraphics = self.createAsset('car', 'Drifting Car', .5, .5);
- self.speed = 5;
+ self.speed = 1;
self.direction = 0;
self.momentum = {
x: 0,
y: 0
@@ -77,12 +77,9 @@
yy = segmentStart.y + param * D;
}
var dx = point.x - xx;
var dy = point.y - yy;
- var distanceToCenterLine = Math.sqrt(dx * dx + dy * dy);
- var roadWidthHalf = segment.width / 2;
- var distanceFromCenterToCar = Math.abs(B) - roadWidthHalf;
- return Math.max(0, distanceFromCenterToCar);
+ return Math.sqrt(dx * dx + dy * dy);
};
self.addRoadSegment = function () {
var lastSegment = roadSegments[roadSegments.length - 1];
zigzag = !zigzag;