@Tirk182 I sort of understand what is going on but not fully.
For the animations, we were using an animstategraph and a script attached to the player model to activate the scripts but if we do that we get the error I first mentioned. The enemy shows the current players animation instead of the action that the enemy is carrying out.
What do you mean by passing a state number in game-room.js?
If you take a look at the current state, I have two animations, for the enemy model, which I want it to show it to current player. I could declare them both in an animstategraph, and a script with it, but I donât understand how it translates over to current player.
In your code you say
player.set // activate state playerAnim
What do you mean by this? How do you access the animation and set it without like referencing the animstategraph?
@Alexis_Shaju I see several ways you handle animation state changes in your code. This was just a placeholder to show you where to set it. You can use one of your methods.
Or you could execute them like this with some changes.
this.entity.anim.baseLayer.play(animation**);
Keep in mind that the instantiated player in the room handled by game-room.js are referenced by player.anim.setBoolean. Because of this const player = this.entity.findByName(actorNr);
For example this is already written in one of the scripts. To what entity do I attach this script to then?
And do I attach this through game-room.js or how does it work?
@Tirk182 So do I add a script component to the player, which is the script I have with the setting to true and false of the animations, through the game-room.js, and add the animstategraph to the enemy template?
GameRoom.prototype.updatePlayerPosition = function (content, actorNr) {
const { x, y, z } = content.position;
const playerData = content.player;
const player = this.entity.findByName(actorNr);
const playerMat = this.app.assets.find(playerData.playerMat);
// Display Actor
this.playerName = player.findByName('State').element;
this.playerName.text = playerData.name;
// Map Color material
player.render.material = playerMat.resource;
// Set the position
player.setPosition(x, y, z);
};
From what I described in my description above this is what is happening here. This script is called every time a remote player is moving and updates their position. All this is handled by the Photon networking and you get passed content along with the actor number. Most important is that one of the things you get passed to you in the function is the remote actors position in all three axis.
In the gaming screen you will have to keep track of in your mind is that x and z translate to the horizontal axis. i.e. your player will go back, forward, left, and right based on these two variables alone.
So if x or z are changing every update your remote player is running or walking. If you detect this in the update then you must play the player.anim.setBoolean(ârunâ, true); or set to false if not moving.
y directly relates to vertical movement. i.e. your remote player just jumped. player.anim.setBoolean(âjumpâ, true); or false if not.
Other thing I noticed is that your player is a pistol and not actually a character.
You are going to want to put the player template in here. Also your player template should include your anim state graph etc. Hope this helps
I think this information helps, I will try it out asap. The Pistol Idle is just the name that the model ended up with when I downloaded it from mixamo with the idle animation.
I have created an animstategraph for the enemy model template which is attached to the game-room.js file and attached it to this model.
What is the best way to detect change in player position?
I see it is first gotten by content.player.
Would something like:
if(x)//then do something
be sufficient to set the animation for when X value changes?
âYes this also could be another route. This attribute could be broadcast from player.js script and added to the data structure passed.â
Would this be the easier method? If so how would I go about it?
There a different ways to do this. You can send for example an integer like 1 and 2, where 1 is your idle animation and 2 is your move animation. I didnât do this myself before, so you have to find out the exact way yourself.