I am taking a small break from Arescape to make the basic engine for my next game(it will be broken into parts for a faster release time and the 1 GB limit) it will be like a classic Zelda-style game so I cannot use Xflip to fix this, and I need the game to detect what direction the player is facing in, however, I cannot find out how to make the laser shot know what direction to fly in, the API reference says that currentClip is what to use but it is not working for me
Can anyone help me with this?
link to script: PlayCanvas | HTML5 Game Engine
Can I have some help figuring out how to fire it?
Iâm not sure how currentClip
is related to your question. I guess you need to copy the rotation of the player entity or use lookAt
to point the laser in the desired direction.
Do you make a 2D game without rotating the entity?
The player doesnât rotate, only the laser blast rotates right now
But for the laser to rotate I need to know where the player is looking so I can angle the Lazer and make it move in the correct direction
Do you want to use the name of the current clip to rotate the laser in the correct rotation?
That is what I am trying because it would most likely be the easiest way that I could think of, but I could not find anything in the API reference site that would help me with it, any tips and scripts will be tested when I get home later today, I am currently away with my family
It seems there is no public way to get the name of the current clip. The best solution is to keep track of the current direction instead.
I have a variable in the player movement script that is checking the playerâs direction to show what the playerâs direction is so I can apply the correct idle and shooting animation, I could try making it a world variable (or whatever the âthis.playerDirectionâ type variables are called)
1 Like
I tried to switch the direction variable to this.direction, but it will not transfer to the blast script so I cannot detect it
You have to create a global variable after the first line of the script without using this
.
var playerDirection = 'Right';
You can set it somewhere else like below.
playerDirection = 'Left';
You can check the variable like below.
if (playerDirection === 'Left') {
// your code
}
thx, however, I have the direction working in the player script however the problem arises when going to the blast script where I am trying to angle the laser blast sprite, I donât know how to make the global variable also affect the blast script. how do I make a global variable that would affect other scripts?
all scripts I have(blast.js is the one I need done tho, and Move Qiste.js needs global varriables): PlayCanvas | HTML5 Game Engine
also, the direction value is measured in degrees, up is 0 degrees, right is 90 degrees, down is 180 degrees, and left is -90 degrees. this is based on how griffpatch named the costumes of the player sprite in the RPG asset pack.
I tried using the detector script âvar value = this.app.root.findByName(âmyEntityâ).script.myScriptName.myPropertyName;â however it is still not moving, how do I fix this?
it is reading the angles now, but the blasts arenât even appearing on screen, they disappear as soon as you shoot, I added a laser-firing sound effect to make sure that they spawn, but they donât appear, I might tried switching translate to translateLocal, but they still dissapeared
btw I edited the update function to make the âthis.app.root.findByName(âmyEntityâ).script.myScriptName.myPropertyName;â thing work
I just accidentally fixed it, I cannot rotate the entity using set rotation except when I first spawn it for some reason
You didnât follow this step and thatâs why you canât use your variable in another script.
This is because you currently only use your workaround in the initialize function of your script. This function is only executed once.