# Search the Community

Showing results for tags 'trig'.

• ### Search By Tags

Type tags separated by commas.

### Forums

• HTML5 Game Coding
• News
• Game Showcase
• Web Gaming Standards
• Coding and Game Design
• Frameworks
• Pixi.js
• Phaser 3
• Phaser 2
• Babylon.js
• Panda 2
• melonJS
• Haxe JS
• Kiwi.js
• General
• General Talk
• GameMonetize
• Collaborations (un-paid)
• Jobs (Hiring and Freelance)
• Services Offered
• Marketplace (Sell Apps, Websites, Games)

• 0 Replies

• 0 Views

### Interests

Found 1 result

1. Hello, I am building an Oceanic game and need to utilize the water surface. I am swimming fish through the sea however at angle '0' I want to fish to be pointing up and not left. I do this by creating the angle 90 degrees: this.xSpeed = Math.cos((this.fishBody.angle+90)/180*Math.PI) * -this.pSpeed; this.ySpeed = Math.sin((this.fishBody.angle+90)/180*Math.PI) * - this.pSpeed; However, I run into problems down the road with AI Fish.prototype.avoid = function(fishBodx, FishBodY, xsp,ysp){ var targetAngle = this.game.math.angleBetween( xsp, ysp, fishBodx, FishBodY ); if (this.fishBody.rotation !== targetAngle) { var delta = (targetAngle) - (this.fishBody.rotation); this.TURN_RATE = 3; // Keep it in range from -180 to 180 to make the most efficient turns. if (delta > Math.PI) delta -= Math.PI * 2; if (delta < -Math.PI) delta += Math.PI * 2; if (delta > 0) { // Turn clockwise this.fishBody.angle += this.TURN_RATE; } else { // Turn counter-clockwise this.fishBody.angle -= this.TURN_RATE; } // Just set angle to target angle if they are close if (Math.abs(delta) < this.game.math.degToRad(this.TURN_RATE)) { this.fishBody.rotation = targetAngle; } } } What is a good solution to this?
×
×
• Create New...