Jump to content

Search the Community

Showing results for tags 'Angle'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

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

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

  1. Hello! I'm trying to make a game like raze (flash game from 2010~ish) and I currently have a level import system and moving animated sprite. I am using matter.js for the physics. I am also using phaser 3 v3.12 as tiled hit detection(? idk how to say) breaks in the the newer versions. I saw the demo for angle to pointer (http://phaser.io/examples/v2/arcade-physics/angle-to-pointer#gv) and wondered if something like it existed in Phaser 3. and also, it would be great if i could anchor a sprite onto another moving one (the weapon on the player) as then it would work, but idk how to do it as I couldn't find anything for phaser 3. Thanks for your help, I might not respond right away! AND here is my project link(so i can work on it on the multiple different computers that I have): https://codesandbox.io/s/k0mq2lj533 ~~~~technically I'm copying the code from the "making modular game worlds in phaser 3 part 5" demo, but this is how I get started on projects as I'm not good at setting things up!
  2. I have done a demo code that creates a gun (blue box) and bullets (red boxes). How can I set the initial position of the bullets depending of the rotation of the gun? Said with other words, if I rotate the gun (left/right arrows) , the bullets keep coming from the top side of the gun (box) instead of rotating accordingly. Code: http://plnkr.co/edit/3evg6J2cGo0nS7QKxiak?p=preview Preview: http://run.plnkr.co/AodG3n4Ykb3osdh2/
  3. Hi, I'm creating a game that player can walk over terrains with lots of slopes. How can I make my player rotate accordingly to the angle of the slope? This is how it's currently working: And this is how is must work (I've changed the angle manually): I'm using Box2D plugin to generate the terrain accordingly to an image. That's the reason of all these bodies. Thanks!!
  4. I am setting up some camera rotation things and I want to know how to lock the camera rotation, so when I move the mouse on the y axis (the camera is pointing at the mouse btw) it is locked to stay looking at part of the screen that for examples sake is above 30% from bottom and below 70% of the scene? Also i want to know if i can set up a mouse hover for movement the pseudo code would follow; -detect mouse position -if position is under 40% from left to middle rotate camera left, if position is between 40-60% rotation left at a slower speed if position is greater than 60% from left to right rotate camera right I currently have it spinning the scene following the mouse, as simple as; function mouseMove(e){ camera.rotation.y = scene.pointerX/1000; camera.detachControl(canvas); } note: the detach control removes the click to drag default feature that i do not want.
  5. Hi everyone! I have actually a problem which is quite stupid but I really need help to solve it: I have a sphere (position 0,0,0) on which I want to "put" a mesh. I have a ray coming from the center on the sphere to a point somewhere in space, and want to put the mesh on the sphere surface, oriented to the center of the sphere, as if the sphere was a planet. I don't find anything in order to rotate a mesh from a ray in Babylon, and all the tries I do with a trigonometric approach aren't satisfying… Here is the code doing that: http://www.babylonjs-playground.com/#C1M3C7 Thanks for your help!
  6. I have an issue where I am using the followCamera in a top down view (think original grand theft auto). It works fine except when I apply impulse to my character/mesh/imposter to where the character moves backwards, the camera rotates a full 180 degrees. I want the camera to stay in the position so that it never rotates. Meaning, the north portion of the map will always be north, regardless of the direction of the character/mesh/imposter the camera is following in the top down view.
  7. Hello fellow HTML5 Game Devs. I have an interesting problem I am testing out some controls and different schemes for my game. I have an image of a fighter. It uses the arcade physics mode. When I press the UP arrow, it goes right.... Code: var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); function preload() { game.load.image('background','../assets/images/deep-space.jpg'); game.load.image('fighter','../assets/images/Human-Fighter.png'); } var player; function create() { game.add.tileSprite(0, 0, 1920, 1920, 'background'); game.world.setBounds(0, 0, 1920, 1920); game.physics.startSystem(Phaser.Physics.ARCADE); player = game.add.sprite(game.world.centerX, game.world.centerY, 'fighter'); player.anchor.set(0.5, 0.5); game.physics.arcade.enable(player); // Notice that the sprite doesn't have any momentum at all, // it's all just set by the camera follow type. // 0.1 is the amount of linear interpolation to use. // The smaller the value, the smooth the camera (and the longer it takes to catch up) game.camera.follow(player, Phaser.Camera.FOLLOW_LOCKON, 0.1, 0.1); } function update() { player.body.velocity.x = 0; player.body.velocity.y = 0; player.body.angularVelocity = 0; if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { player.body.angularVelocity = -200; } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { player.body.angularVelocity = 200; } if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.physics.arcade.velocityFromAngle(player.angle, 300, player.body.velocity); } } function render() { } If you can help, it would be greatly appreciated! Thanks!
  8. 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?
  9. Hello guys, I am using the sprite for a shot from a gun effect. How I can rotate Y axis of a sprite? I need somthing like on screenshot. My sprite: It screen I did in the photoshop to give an opportunity to understand what I need
  10. I´m having a problem with the weapon plugin. When I use the function weapon.fire() it fires a bullet 90 degrees from the canon sprite (the one the weapon plugin is tracking). Any idea what I am doing Wrong? Thnxs!
  11. Hi everyone, I have an animated sprite of a meteorite with it's tail. I need that the collisions are only for the rock and to be able to rotate the sprite with the movement direction. If I setup the body size like this: this.anchor.set(.55, .55); this.body.setSize(110, 110, 400, 350); The graphic and body collision is fine if the angle of rotation is 0. But I need to rotate the sprite around the anchor point and then the body is not on the desired position of the sprite. How can I fix this?
  12. I am back with another crazy thingy! I have here for your pleasure, a playground! http://www.babylonjs-playground.com/#28AM9V#1 I have some notes at the top of the playground but let me break this shiz down for you. I am trying to modify the arcRotateCamera's beta based on mouse wheel scroll. I have this sort of working.. well, it does work... BUT, I am having trouble with it; it's choppy and just not right. I'm trying to get it smooth like butter (have easing). The idea is the closer you get to the target, the beta changes so you go from a top(ish) view to more of a 45-40 degree angle looking at the target. Make sense? I just made a hand motion explaining but you can't see it.. trust me.. I did it. I added some textures to help you see the choppiness. My guess, is I need to maybe use a percentage of a range for the scroll/angle, but I have no clue; math and I do not get along. I could be wrong on that.. not about math and I not agreeing, that I am sure of. I tried calling the angle/scroll event in various places (registerBeforeRender/AfterRender) to try and determine why it's choppy but there was no change. I was hoping someone smarter than I am could take a look and provide some feedback. tldr; I suck and need help. thanks.
  13. I'm trying to make a 2d space game involving a sort of space dogfight between the player and some ai bots. I need help with the enemy ship automatically rotating towards the player, but not being exactly pointed towards the ship 24/7. I want the enemy ship to have some "lag" in its response to the player's movement so it's more realistic. Right now I have a model which is not realistic and would probably be too hard for the player to win: update: function(){ //blah blah var tempAngle = Math.atan2(fightSprites.player.y-fightSprites.enemy[i].y, fightSprites.player.x - fightSprites.enemy[i].x); //gets angle between player and enemy fightSprites.enemy[i].body.rotation = tempAngle + (3.141/2); //too precise }
  14. I have a demo at http://www.babylonjs-playground.com/#1JMZWJ#11 What I am try to do is create a cylinder between two points, but it seems calculation for y-axis doesn't work. in the demo I move the target in all three directions (x,y,z) and I can clearly see the cylinder doesn't connect two points, but if I comment away the movement of y axis, the angle seems to be correct, I am really puzzled, can anyone help me? I am new at 3d programming and new at BabylonJS
  15. Hi Guys, So I'm flying a space ship using the accelerometer and gyro.js, with gyro.js I calculate the angle the ship is flying in. Now I want to fire a laser when I touch my mobile device's screen. The laser should fire in the direction the ship is flying in, no matter where the user touches the screen. I've searched for a couple of hours, but still didn't find a way to make this work. Any ideas? function fire(angle) { if(game.time.now > bulletTime) { bullet = bullets.getFirstExists(false); if(bullet) { bullet.reset(player.x, player.y + 8); bullet.rotation = this.game.physics.arcade.moveToObject(bullet, game.input.activePointer, 500); bulletTime = game.time.now + 200; } }}This is what I have got so far, and this works. But it doesn't fire in the direction the ship is flying in. ps. I've calculated the angle with the following code: var anglePlayer = Math.atan2(o.y * 20, o.x * 20);anglePlayer *= 180/Math.PI;anglePlayer = 180 - anglePlayer;player.angle = anglePlayer;
  16. Hello, I'm having an issue with setScaleMinMax property on sprites, I have two sprites, parent and child, the child is set to a min/max scale of .5 and the parent is scaling freely, I'm having odd results when scaling the parent. The parent also rotates, in some angles the child maintains the scale but in others it scales, what can I do to prevent the child from scaling? Thanks.
  17. Hello, I saw a post about limiting camera zoom and direction. However, I want to limit camera to a "top-down" only view. Zoom in and out is acceptable. Probably leave that alone. But I want to restrict the ability to rotate the view. Is it doable? If so how? Thank you...
  18. Hi everyone! I don't really know where I should post this, thus I post it here. Maybe it's inappropriate, so please tell me where its rightful place may be. I've come across some kind of a bug (maybe intended) and I'd like to suggest a fix. In the arcade engine, the angleBetween() method uses the x / y coordinates of the targeted sprites, and I think it should use the world.x / world.y coordinates instead. In my use-case, I had a character with a child sprite, its gun, that I wanted to point to the player. Because the gun was a child sprite, the angle was not correct and the gun wouldn't target the player. What do you guys think? Are there use cases where it should be x / y instead of world.x / world.y? Maybe I should have used another method like angleToXY(), but I still kind of feel like angleBetween() should be fixed. Also, I apologize in advance if this has already been debated over. If so, a link to the previous post would be great! Have a nice day guys!
  19. Hey guys! thanks for all the answers in the other topic, those helped me a lot ;). I have a doubt, how can I set a min angle and max angle for my camera rotation? because I don't want my camera to rotate 360° . What I tried is to let a little box to follow the camera and it has a collision with some walls in order to stop showing the part I don't want to. it worked but the effects are really ugly. That's is solution, as I mentioned It's has some ugly effects and is not always exact. var prevTarget= jQuery.extend(true, {}, camera.getTarget()); //OP1 scene.registerBeforeRender(function () { for(var i in objs)//the walls I mentioned if (objs[i].intersectsMesh(sphere, true) && scene.isReady()) camera.setTarget(prevTarget); prevTarget= jQuery.extend(true, {}, camera.getTarget()); }); //or //OP2 (more precise) setInterval(function(){ for(var i in objs) //the walls I mentioned if (objs[i].intersectsMesh(sphere, true) && scene.isReady()) camera.setTarget(prevTarget); prevTarget= jQuery.extend(true, {}, camera.rotation); },0.1); I hope a better way to do it, thanks guys for supporting us
  20. When I change a sprite it's rotation with *.rotation, *.angle or *.pivot, it also changes the position because the center of the sprite will change. I'm making a game with a grid and it makes my sprites fall out of their tiles, how can I prevent this? Also here are some example pictures: Normal http://i.imgur.com/V8FRJ3M.png Anchor 0.5 http://i.imgur.com/xLoEpZi.png Angle 90 http://i.imgur.com/x1YtRnn.png
  21. I'm trying to create a simple game involving a fish following the pointer by replicating and modifying this code: http://gamemechanicexplorer.com/#homingmissiles-1 (BTW great site for noobs.), but the entire missile/fish rotates towards the pointer in this example, while I don't want the sprite to rotate. How can I achieve this? Also how can I add animation to the missile while it is chasing and while it is turning by 180 degrees? Any help is appreciated.
  22. Hello ! Why does the start angle of an arc is acting weird when it is set to anticlockwise ? You can see it in this example : http://phaser.io/examples/v2/display/arc-details The start angle is moving... In fact, i'm trying to make a piechart so i need it to start in the right place.
  23. I need to rotate a sprite, according to the pointer. Phaser has the following code to do this. angleToPointer: function (displayObject, pointer) { pointer = pointer || this.game.input.activePointer; var dx = pointer.worldX - displayObject.x; var dy = pointer.worldY - displayObject.y; return Math.atan2(dy, dx);}Given this code, and reviewing the Class Vector in panda.js 2.0. In documentacionhe it is seen that has two methods which are: angle and angleFromOrigin. angleFromOrigin: function(vector) { return Math.atan2(vector.y, vector.x) - Math.atan2(this.y, this.x);} //This method is very similar to Phaser.which try to access them and have failed. in the following way game.vector.angleFromOrigin()I could not access because this method. the easiest way to recreate the phaser method.It is on the scene in the mousemove add the following method. mousemove: function(x,y,id,e){ var dx = e.x - this.sprite.position.x; //Took the pointer value in x, and rest with the last posision x, just like the method is doing phaser. var dy = e.y - this.sprite.position.y; this.giro = Math.atan2(dy,dx); this.sprite.rotation = this.giro;},Ok, the sprite makes its rotation. but not rotate with the movement of the pointer.
  24. Hi, yesterday i was struggling with rotation of an enemy. In my game you drive a spaceship and the enemies should rotate to your location in the nearest way (left or right), so they can follow you. This seems to be simple, but i find some problems in the rotation degrees. First i have to find the angle that the enemy should have, to point to my spaceship. I find two ways to do it. The first doesn't work: angle = game.physics.arcade.angleBetween( this , player ); // returns angles between something like 3.1 and -3.1// ( this = Enemy class )I don't know why. Maybe because i am using p2 physics and not arcade? The second works: angleRadians = Math.atan2(this.position.y - player.position.y, this.position.x - player.position.x);angle = Math.atan2(this.position.y - player.position.y, this.position.x - player.position.x) * 180 / Math.PI;// returns 180 to -180So i use that instead. Here I find something strange, the 0° angle in the Enemy is on Top. But, the 0° angle returned in the var angle is on the left. ( both ways in clockwise ) Finally i try doing something tricky like this, but doesn't work properly: if( this.body.angle+180 - angle-90 <= 180 && this.body.angle+180 - angle-90 >= 0 ){ this.body.angle += .6;}else{ this.body.angle -= .6;} May if I figure out why the degrees are different, i can get it work. Thanks!
  25. Is it possible to change the default 0 point of a sprite's rotation? So when a sprite rotates to say 135*, 135* becomes the new 0 point? Help is greatly appreciated!
×
×
  • Create New...