- Home /
Does moving a charactercontroller via it's transform hurt performance?
Does it need to recalculate the collision data of the scene every frame? Should you only move a CC with the move functions?
I ask because I'm trying to determine the best way to handle proxy players in a network environment. The easiest solution with the least bandwidth usage would be to just modify the transform on proxies, but I'm not sure how badly it will hurt performance.
Everyone knows UnityAnswers is for wasting time at your day job, where you are pondering Unity quandaries that you can't test at work!
Answer by Matt-Downey · Aug 31, 2012 at 07:00 PM
I'm almost positive transform.Translate is cheaper than rigidbody.MovePosition.
If you use rigidbody.MovePosition, the object will sweep out the space afaik to make sure the object interacts with all of the other objects in it's path. If you wanted realism in a sea of soccer balls for example, MovePosition would probably push the objects in front of you outwards in waves through physics (with a little extra overhead), whereas transform.Translate would push them out of the position to which the player teleported (not moved), which could make the soccer balls behave more erratically as the player reached higher speeds.
Also, If I'm not mistaken, rigid.MovePosition will not move to the position it is told to move to per se. In reality rigid.MovePosition will try to move to a position, but if it's path is blocked it will try to get as close as possible.
transform.Translate will probably be cheaper, since it is a form of teleportation that doesn't use physics at all.
The rigidbodies interact with colliders and physics more than the transform afaik. For instance, rigidbody has a SweepTest function, which determines the first collision between an object and its environment if it were moved. The transform class on the other hand has no such functions.
So yeah: rigidbody-->physics; transform-->teleportation
[edit:] and since you are using CharacterController.Move that is going to be even more expensive than physics in most likelihood, since it has to calculate everything related to move in the CharacterController script and then perform physics.
$$anonymous$$akes sense so I would agree, that useing the transform to move would save lots of bandwidth and give better performance since it doesn't have to run the physics for it.
Usually people send 1) input over the server 2) the desired position or 3) the delta vector (small change in position). You can send more (often redundant) information but for the most part you should just send the position, input, or the change since the last frame.
Running physics is going to overload the CPU and slow down the game, but that has nothing to do with bandwidth.
The colloquial lag the player perceives could either have to do with unresponsiveness from bad ping time that isn't compensated by client side prediction or it could be from your game overloading the CPU.
You seem to be talking about lag caused by overloading the CPU, which might more accurately be called something else, usually the lag (when correctly termed) has to do with bad connection to a network.
Regardless, you don't want to make a ton of calculations, so it's good practice to start by just sending the position of the player over the network for now:
if you want to try to optimize, look into the types of data that can be sent over the network:
http://docs.unity3d.com/Documentation/ScriptReference/BitStream.Serialize.html
and an approximate cost (it might be more due to sending variable names or less due to compression; I have no idea):
http://www.cplusplus.com/doc/tutorial/variables/
char ~= 1 byte float ~= 4 bytes, etc
You should listen to what $$anonymous$$att says - there are many confusions stated about networking in the other posts and $$anonymous$$att has cleared it up.
Also just so you know as a very general principle. It is petty much utterly inconceivable that the amount of information you are sending makes any difference whatsoever. You're out by orders of magnitude worrying about that.
So again every word of $$anonymous$$att's here is gold, I suggest to all readers to study it !
Thank you very much for the words of praise. You made my day!
Your answer
Follow this Question
Related Questions
Character controller not following moving parent transform properly 3 Answers
Instantiate VS Transform 1 Answer
CharacterController Move vs. SimpleMove 1 Answer
Is it possible to get transform.Translate() to move like CharacterController.Move()? 0 Answers
Expense of CharacterController.Move 0 Answers