Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Javascript-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
//Update positioning var frontWheelX = this.pos.x + this.wheelDistance/2 * Math.cos(this.rotation); var frontWheelY = this.pos.y + this.wheelDistance/2 * Math.sin(this.rotation); var backWheelX = this.pos.x - this.wheelDistance/2 * Math.cos(this.rotation); var backWheelY = this.pos.y - this.wheelDistance/2 * Math.sin(this.rotation); backWheelX += this.speed * tick * Math.cos(this.rotation); backWheelY += this.speed * tick * Math.sin(this.rotation); frontWheelX += this.speed * tick * Math.cos((this.steerAngle + this.rotation)); frontWheelY += this.speed * tick * Math.sin((this.steerAngle + this.rotation)); this.pos.x = (backWheelX + frontWheelX) / 2; this.pos.y = (backWheelY + frontWheelY) / 2; this.rotation = Math.atan2(frontWheelY - backWheelY, frontWheelX - backWheelX); |
Dieser Beitrag wurde bereits 5 mal editiert, zuletzt von »Thurien« (07.05.2015, 09:41)
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Thurien« (07.05.2015, 10:45)
Javascript-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
seek: function() { if (this.target != null) { this.steeringForce = _uv2.subtractVectors(this.target, this.drivingFocus); this.steeringForce = _uv2.normalize(this.steeringForce); this.steeringForce = _uv2.multiplyScalar(this.steeringForce, this.maxSpeed); this.steeringForce = _uv2.subtractVectors(this.steeringForce, this.velocity); } }, arrive: function() { if (this.target != null) { this.steeringForce = _uv2.subtractVectors(this.target, this.drivingFocus); var distance = _uv2.length(this.steeringForce) if (distance > 0) { var speed = distance * 1.5 * 0.5; speed = Math.min(speed, this.maxSpeed); this.steeringForce = _uv2.subtractVectors(_uv2.multiplyScalar(this.steeringForce, (speed/distance)), this.velocity); } } }, calculateSteeringForce: function() { this.steeringForce = {x: 0, y: 0}; this.arrive(); }, /** * Updates the car */ update: function() { //Calculate steering forces this.calculateSteeringForce(); //Update velocity this.velocity.x += this.steeringForce.x * tick; this.velocity.y += this.steeringForce.y * tick; //Check if current speed is not bigger than this.maxSpeed var currentSpeed = Math.sqrt(this.velocity.x * this.velocity.x + this.velocity.y * this.velocity.y); if (currentSpeed > this.maxSpeed) { this.velocity.x = this.velocity.x / currentSpeed * this.maxSpeed; this.velocity.y = this.velocity.y / currentSpeed * this.maxSpeed; } //Calculate new front-wheel position this.pos.x += this.velocity.x * tick; this.pos.y += this.velocity.y * tick; } |
Quellcode |
|
1 |
var speed = distance * 1.5 * 0.5; |
Werbeanzeige