- Home /
Animation Update for the TPS controller
Hello there,
Well i am trying to program a small social multiplayer game with only a few functions such as running around,chatting, an inventory with clothes and well the clothes!
so far im done with the chat, names being displayed over the players head and the position updates across the network putting the more complex stuff with the clothes aside my current question is
how can i play animations over a network?
for the position update i just used RPCs but everytime im trying to use those for my animations it says that there is no object attached and it has to be one attached...
im using the standard tps controller provided by unity with that builder guy with a unity symbol on his stomach and the yellow helmet.
my attempt was to acces what current characterstate of the controller script is, define a number for every state and then send it to the network with an RPC call i used a float variable for that
than i wanted to write a script that takes that number and based on the number which came in it plays a specific animation
all i actually succesed with a script that gets the state of the charactercontroller defined as a number (float) but i cant get it sent as an RPC because it always says there is no object attached... but i have attached the script to an object! to the player! same with the animation it says no object attached...
well i know that the tps controller actually also does cross fading and changes the animation speed based on how fast the character is but i would be happy if i would at least see other player run instead of flyign around...
well i hope you guys could help me out !
thanks in advance!!
best regards
Answer by Kacheek · Jun 06, 2013 at 06:02 AM
well i pretty much found kind of a solution instead of sending the other players what animation one player is currentle using ive mad every client to figure out which animation to play by checking the speed other character have for example if they move slower than 0.1 a sec they idle if its under 1 a sec (or so) they walk if its faster they run just jumping doesnt work yet...
heres the code for it! just type it in the standard character controller
function Awake () {
if (networkView.isMine == false) {
InvokeRepeating("animationUpdate", 1, 0.3f);
}
}
function animationUpdate ()
{
if(Vector3.Distance(myTransform.position, lastPosition) >= 1.2)
{
lastPosition = myTransform.position;
_animation.CrossFade(runAnimation.name);
}
else
{
if(Vector3.Distance(myTransform.position, lastPosition) >= 0.15 && Vector3.Distance(myTransform.position, lastPosition) < 1.2)
{
lastPosition = myTransform.position; _animation.CrossFade(walkAnimation.name);
}
else
{
_animation.CrossFade(idleAnimation.name);
}
}
}
Your answer
Follow this Question
Related Questions
how to make game object animation without animator visible to all players in photon pun? 2 Answers
Network Animator not syncing with Clients in Netcode 0 Answers
hi i need help with code 1 Answer
How to use RPC functions to animate other players 1 Answer
Unity MLAPI ServerRPC not getting called 2 Answers