Search the Community

Showing results for tags 'position'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Coding and Game Design
  • Frameworks
    • Phaser
    • Pixi.js
    • Babylon.js
    • Panda.js
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Found 88 results

  1. Hello, i am again... i have a realy noob question but cant find an answer. Since i playing with this Playground i try to figure out how i can get the position of the car (mesh = carBody ?) Im not successful. Line 42 - 44 scene.registerBeforeRender(function(){ console.log("Poisition", carBody.position); }); The only thing that changes is when i turning the steering wheel. Nothing about the position on the ground... I tought the carBody "merge" all meshes into one and move them around with them. So that the positions property on child meshes a relative to the parent mesh. I dont get it...
  2. hi, I have a physic body which should be static on the ground, but I log it's position, and it actually keep changing slightly, why? https://playground.babylonjs.com/#KQBGAR
  3. Camera following with delay

    Hi guys, First excuse me for my english. I want the camera to follow a sprite and I set the position of this sprite every frame. function create(){ this.player = new Player(this.game); this.playerController = new PlayerController(this.game, this.player); this.cameraTarget = this.game.add.sprite(this.player.x, this.player.y, "cameraTarget"); this.cameraTarget.anchor.setTo(0.5, 0.5); this.camera.follow(this.cameraTarget); } function update(){ this.playerController.move(); this.cameraTarget.x = this.player.x; this.cameraTarget.y = this.player.y; } This work but the camera have a small delay, here is some picture of this (red = player, yellow = cameraTarget). Not moving : Moving to the right : Moving to the left : You can see the delay of the camera with the yellow box's offset (Trust me the yellow box is always centered on my screen). The stranger thing is when I set the follow of the camera on the player it work well, no delay. Don't tell me to set the follow of the camera on the player plz, I need this cameraTarget for later calculations. Here is the gitHub if you want the code : https://github.com/JohnyBro/Platformer If someone can help me with this it will be appreciated.
  4. Understand toLocal result

    I'm reading some tutorials about pixi.js and I can't understand the result I got from toLocal. I expect the result to be 100,100 however I got 200,200. Console output: bunny1: 100 100 bunny2: 200 200 200 200 Code: // create our little bunny friend..S var bunny = new PIXI.Sprite(texture); bunny.interactive = true; bunny.buttonMode = true; bunny.anchor.set(0.5); bunny.scale.set(1); bunny.x = 100; bunny.y = 100; // create our little bunny friend..S var bunny2 = new PIXI.Sprite(texture); bunny2.interactive = true; bunny2.buttonMode = true; bunny2.anchor.set(0.5); bunny2.scale.set(1); bunny2.x = 200; bunny2.y = 200; // add it to the stage app.stage.addChild(bunny); app.stage.addChild(bunny2); console.log("bunny1:",bunny.x,bunny.y) console.log("bunny2:",bunny2.x,bunny2.y) console.log(bunny.toLocal(bunny.position, bunny2).x,bunny.toLocal(bunny.position, bunny2).y)
  5. Hello, guys. I'm newbie on 3d programming. I want to display sprite like GUI that has a function linkWithMesh. but it hasn't. In this example, sprite's position from a mesh is changing, not fixed. https://www.babylonjs-playground.com/#87HQN6 the mesh must have BILLBOARDMODE_ALL. how to make sprite to track mesh's position like GUI's linkWithMesh.
  6. What is the BEST way to move a camera by position... When using one of the built-in cameras ... you get good smooth movement... If I try to manually move the camera around using camera.position I don't get the desired effect. I can move the camera around using code like this (delta movements from input): public updateCameraPosition(camera: BABYLON.FreeCamera, horizontal: number, vertical: number, speed: number): void { if (camera != null) { var local = camera._computeLocalCameraSpeed() * speed; var cameraTransform:BABYLON.Matrix = BABYLON.Matrix.RotationYawPitchRoll(camera.rotation.y, camera.rotation.x, 0); var deltaTransform:BABYLON.Vector3 = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(horizontal * local, 0, vertical * local), cameraTransform); camera.cameraDirection = camera.cameraDirection.add(deltaTransform); } } but when I just try set camera position... its funny (I know that vague)... But it would hard to show with all the "Test Project Code" I am using to learn how to move a camera around "Unity-Style" Just wondering of simply setting camera.position (on a universal camera) should give me free range movement like a unity camera.
  7. Failing miserably with alignTo()

    Currently making a menu, I have a bunch of buttons, that are essentially groups containing the button sprite itself and text. Trying to vertically align each subsequent group with their previously added button sprite inside the group (since we can't directly alignTo() groups). The code is essentially how it reads below: let rect, buttons; let InitState = { preload: function() { let square = this.game.add.graphics(0,0); square.beginFill(0xFFFFFF,1); square.drawRect(0,0,200,100); rect = square.generateTexture(); square.clear(); }, create: function() { buttons = this.game.add.group(); buttons.position = {x: 50, y: 50} let btnarray = ["ONE","TWO","THREE","FOUR","FIVE"]; btnarray.forEach(function(btnTxt) { let buttonGroup = this.game.add.group(buttons); let image = rect; let buttonImg = buttonGroup.add(this.game.make.button(0,0,rect)); let txt = buttonGroup.add(this.game.make.text(buttonImg.width/2,buttonImg.height/2,btnTxt)) txt.anchor = {x: 0.5, y: 0.5}; if(buttons.children.length>1) { // We won't be needing to align the first one buttonGroup.alignTo( buttons.getAt(buttons.children.length-2).children[0], // buttonImg Phaser.BOTTOM_LEFT, 0, 4 ); } }.bind(this)) }, } let Game = new Phaser.Game( 800, 600, "", Phaser.AUTO, InitState ); This is a simplified version of what I'm doing, but even in this simplified version, the same thing occurs. The first and second buttons are correctly placed, but the third one is positioned in top of the second, and the fourth in top of the third. As you can see on the picture below, we can only see the first and last buttons, because the rest is buried under "five". alignTo() always refers to the second-to-last button in the group (the last being the one I'm trying to move), so why it seems to always take position (0,0) (relative to buttons) as reference? Thanks in advance.
  8. Hello, I cannot figure out how the get an updated Bounding Box after the rotation, position or scaling of a mesh. Here the playground: https://www.babylonjs-playground.com/#5HP8KU#1 Thanks in advance for the help
  9. Locked Axis

    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.
  10. function addSphere(scene, { x, y, z }: Object, diameter: number = 0.05, color = new BABYLON.Color3(0, 0, 0)) { const sphere = BABYLON.MeshBuilder.CreateSphere("sphere", { diameter }, scene); const material = new BABYLON.StandardMaterial("texture1", scene); material.diffuseColor = color; sphere.position = new BABYLON.Vector3(x, y, z); sphere.material = material; } const positions = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind); const zeroCoord = { x: positions[0], y: positions[1], z: positions[2], }; addSphere(scene, zeroCoord, 1); Demo As you can see in the code, I am just trying to get vertices of the foot. and the placing a sphere on the first vertice of the foot. But for some reason, as can be seen in demo, the sphere is added somewhere not even remotely close of the foot. You can download the mesh here. Why is this happening ? I've been trying to fix this for two days now, but I can't seem to do it. Edit: I am using babylonjs exported for blender. Edit2: Added playground url https://www.babylonjs-playground.com/#EEKFSK#2
  11. Hi all, is it possible to disable camera movement except rotation, so as to get a streetview-like camera ? I prepare a playground : http://www.babylonjs-playground.com/#K4TSQD Here we have a sphere, with a spherical texture mapped on it, camera is placed on its center, and all we want for now it that user can't move, but still can look around. Is their a way to override movement settings, or other tweaks ? Thanks for helping
  12. Is it possible to get the absolute rotation of a child mesh, in the same way it is possible to get the absolute position of a child mesh via mesh.getAbsolutePosition?
  13. i just had a problem to calculate the camera position to fit all kinds of size of meshes. this pg make the mesh in the center of the screen (you can change the ground size), but not working on mobile devices. don't know why. https://www.babylonjs-playground.com/#P6JAWE
  14. I have been having problems when I scale my gamemaker 2 html5 game to fit the height of the browser. Once it scales up it no longer detects the mouse position. Without it being scaled to height I am able to click on my enemies, but when it is scaled to browser height I am unable to. I figure it has to do with the scaling to the browser height Thanks in advance! if(os_type == os_windows){ ideal_width = 0; ideal_height = browser_height; start_b_width = browser_width; start_b_height = browser_height; aspect_ratio = browser_width/ browser_height; ideal_width = round(ideal_height / aspect_ratio); if(ideal_width & 1){ ideal_width++; } room_set_width(rm_game, ideal_width); room_set_height(rm_game, ideal_height); surface_resize(application_surface, ideal_width,ideal_height); room_goto_next(); alarm[0] = 60; } //In my alarm window_set_size(room_width,room_height); window_center();
  15. Hi there! So here's my issue. I have a player sprite which has an orb sprite attached to it as a child. Player = function (game, x, y, image) { Phaser.Sprite.call(this, game, x, y, image); //calls constructor this.orb = this.addChild(game.make.sprite(0, 0, 'orb')); game.add.existing(this); }; /*--------------------------------------------------------*/ Player.prototype = Object.create(Phaser.Sprite.prototype); Player.prototype.constructor = Player; /*--------------------------------------------------------*/ I want to reference the x and y positions of the orb so that I can shoot bullets out of it. BUT, if I console.log(this.orb.x) or the y position, the value that is returned is 0. What do I do so that I can get the x and y positions of the orb, relative to the game world and not the parent sprite??
  16. in my scene I have created 3 cameras (free camera) in a blender SCENE and exported the scene, I want to get that camera in a different variable so I can use them to switch in between them. Is there anyway I can get those cameras from code like getMeshByName or getCameraby name. can anybody direct me the proper way?
  17. SET position of OBJ object

    Hi all, Are there any way to set my import mesh (obj) to height of ground? I have done something similar with SPS but in this case I have to do this with differents meshes which have been imported to scene. Thanks!
  18. Hey Guys! I am making a game when I need the player to look at mouse pointer. I implemented this. But Phaser seems to be giving coordinates only inside canvas bounds. which gives effect like this: demo I get mouse coordinates like this: lookAtMouse() { const mouseX = this.game.input.mousePointer.worldX, mouseY = this.game.input.mousePointer.worldY; this.lookAt( mouseX, mouseY ); } lookAt( targetX, targetY ) { const targetPoint = new Phaser.Point( targetX, targetY ), entityCenter = new Phaser.Point( this.body.x, this.body.y ); let targetAngle = ( 360 / ( 2 * Math.PI ) ) * this.game.math.angleBetweenPoints( targetPoint, entityCenter ) - 90; if ( targetAngle < 0 ) { targetAngle += 360; } this.angle = targetAngle; } Is there any way that I can get mouse coordinates outside of the canvas ?
  19. tl;dr when I move parent, child position is updated too late, how to manually force to update child position when I move parent? Hello, in my game I have a group of sprite objects (Ships) this.shipsGroup = game.add.group(); Each Ship before adding to this.shipsGroup have two other groups as children : var actualShip = game.add.group(); var surrounding = game.add.group(); for (var m = 0; m < 3; m++) { var temp = game.add.sprite(-halfSize - 50 + l*50, tempy, 'red'); temp.anchor.setTo(0,1); tempy+=50; if(m == 1 && l > 0 && l < ship.unitSize+1) { actualShip.add(temp); } else { surrounding.add(temp); } } ship.addChild(actualShip); ship.addChild(surrounding); this.shipsGroup.add(ship); Note: every child object has position relative to parent (so child position (0,0) is on parent) Everything is fine up to this point. I'm moving my ships using something like that in every possible direction (I'm moving them on 50x50grid). This check is in update method of game. if(this.draggedShip.position.x - game.input.mousePointer.x >= 50 && some_boundary_condition) { this.draggedShip.position.x-=50; this.checkOverlap(); } So, after my ship has moved to next grid, I'm calling checkOverlap function to check on top of which grid fields actually is the ship. (I have seperate group of sprites for each grid field) checkOverlap: function() { for (var i = 0; i < this.draggedShip.children[0].length; i++) { for(var j = 0; j < this.fieldsGroup.children.length; j++) { if(this.draggedShip.children[0].children[i].overlap(this.fieldsGroup.children[j])) { this.fieldsGroup.children[j].alpha = 1; } } } }, What is wrong : it looks like sprite.overlap uses OLD children positions (before parent move). So when I move my ship 1 field to the left, the result of this checkOverlap function are fields where the ship was in previous step. How it should be: children positions should be updated before my checkOverlap call. How can I force to do it? I was trying to call update on childrens but it didn't work. Phaser 2.6.2
  20. I have an imported, animated, rigged character mesh. I want to move its z position on keyboard input. I'm not seeing a position attribute on the Skeleton or on the Bones. I'm not seeing an obvious way to do this. playground at: http://babylonjs-playground.azurewebsites.net/#2F6AQS#2
  21. In http://babylonjs-playground.azurewebsites.net/?15 it appears that setting light.position has no effect. I made http://babylonjs-playground.com/#AX6IZ and the same. What am I missing?
  22. Hello everyone, http://babylonjs-playground.com/#RZGEH#0 In the example above, on the left should be exactly what's on the right. But, the mesh should stay in place, I don't want to change its position to compensate for the new pivot point. ajustPosition bellow should be 0. var offsetUnit=2; var ajustPosition=offsetUnit; var box1 = BABYLON.Mesh.CreateBox("box1", 2, scene); box1.position.z = -2+ajustPosition; box1.setPivotMatrix(BABYLON.Matrix.Translation(0, 0, -offsetUnit)); How to set the pivot point and keeping the mesh in place without changing its position?
  23. Hello ! In the mesh object, there is an array called subMeshes containing the different materials applied to the mesh. It would be cool to be able to access to the position of the "submesh". For example, a black textured material for the boots and we can get the center position of the boots. It sounds maybe useless because some materials are applied everywhere so : a way to access to the position of a specific part of the mesh, a vertex group (in Blender) for example. Is there a way to access to the position of a bone in world global space and then copy this position for a mesh (without attachToBone) ? I tried to check the numbers in all the matrices included Worldmatrix but it doesn't give the right thing. Thx for your attention.
  24. Hi, Im looking for a way to place objects relatively to other nested objects. ( objects that have a chain of parents that have been moved, rotated ). I searched the docs but couldnt find anything that could do what im looking for. Ive tried position.add / addToRef etc but they dont take object's rotation/parent chain into account. An example of what id like to do: A player turns 90 degrees in x direction. A weapon that is parented to the player, turns another "n" degrees. Now, how would i put a bullet at the tip of the weapon. ( without setting its parent = weapon ). After the bullet is created, it would move/follow objects in global space/coordinate system. in pseudo code: bullet = new Bullet();//extends Mesh. bullet.position = player.weapon.position.clone().translate(BABYLON.Axis.Z, weapon_barrel_length, BABYLON.Space.LOCAL); Note: position object doesn't have translate function, only mesh. My actual case is a bit different but this example explains it better.