Hot answers tagged


The issue in your code is that you only check for the key press in the OnTriggerEnter function, which only gets called when the collider enters the trigger. What you probably want to do instead is check for the keypress inside the OnTriggerStay function, which gets called while the collider lies inside the trigger.


You can solve this with some basic trigonometry. I wrote the code in Unity, but the general idea should be the same. Consider the following image: We already have P1 and P2. Here is some code to calculate the rest with comments: //Get points P1 and P2 based on circles Vector2 p1 = A.transform.position; Vector2 p2 = B.transform.position + ...


Is the script attached to the game object of one of the two chests CurrentChest and OpenChest? Then keep in mind that deactivating a game object also deactivates all scripts attached to it. That means any events on them won't fire anymore. You likely only want to disable specific components of the chests.


I think you can't do it. Phaser groups doesn't have body: But you can use setAll method to set properties to all sprites of a group: Otherwise, if you want more complex objects you could try another type of physics (P2) and make complex bodies with polygons.


It turns out that the image was to large for the size I wanted it to be, so I was only seeing the corner of it (which was blank).


Nevermind, guys. I fixed the problem.. the reason why all the images are showing at the center of the screen is because of the "this.monsters =;" and the " monster = state.monsters.create(,, data.image);" code. Now, the "x" serves as the horizontal position of the images and it should be ...


Your main problem is that you did not account for the discontinuity in the arctangent function... // Check if arctangent has crossed the discontinuity if (delta < -Math.PI || (delta > 0 && delta < Math.PI)) { And you are not reducing the player rotation into a canonical -Pi <= x < Pi range. // Reduce player.r into the -PI thru PI ...


Minerals/items are gameObject, not Transform. Your instantiation code at DestroyRock() should be like: Instantiate(minerals[Random.Range(0,1)], position, Quaternion.identity); In minerals[Random.Range(0,1)] 0 and 1 are index of the minerals array. If there were 5 items it would be minerals[Random.Range(0,5)].


I have it :) var blockHeight = 15; var blockWidth = 30; var zoom = 2; for (var x = 0; x < 10; x++) { for (var y = 0; y < 10; y++) { var screenX = Math.floor((x * (blockWidth * zoom - zoom * 2) / 2) + (y * (blockWidth * zoom - zoom * 2) / 2)); var screenY = Math.floor((y * (blockHeight * zoom - zoom * 1) / 2) - (x * (blockHeight * zoom - ...


Not sure i (bother to :-)) understand your code, but i'd like to point out that accumulated time will never be accurate on the long term. If it is crucial that you have consumed exactly 2500 frames in 100 seconds, you likely cannot rely on exact sum of the individual frames. Instead you must make it "absolute". If you require 25 ms per frame, you know for ...

Only top voted, non community-wiki answers of a minimum length are eligible