Hi! My player prefab is a simple robot with two animations (run and idle). It have a Character controller so I can move it! The problem is: It pass trough the objects (except for the floor)! But every objects has the mesh collider!
Why?? Thanks
Hi! My player prefab is a simple robot with two animations (run and idle). It have a Character controller so I can move it! The problem is: It pass trough the objects (except for the floor)! But every objects has the mesh collider!
Why?? Thanks
help!!
Four things you can check.
Make sure that the Colliding Objects are not triggers. Check their Colliders. If the isTrigger option is true, then they ignore physics, including collisions with your player character.
Check the layers of the Colliding Objects. If you use different layers on each object, then open your Physics Manager from Edit > Project Settings > Physics and expand the Collision Matrix table. Make sure that the Colliding layers have their boxes checked. If they don’t, Unity doesn’t calculate physics and collisions for the 2 interracting layers.
Check the time settings under Edit > Project Settings > Time. You want to look at the fixed timestep rate here. This is the value that tells Unity how often to check for Collisions in seconds. Default is every 0.02 seconds (a good, average number). If you have increased this value for performance reasons (physics were lagging the game) and your player moves fast, he may be able to pass from one side of the Collider to the other before Unity has time to calculate physics. This can cause you to pass through objects.
Check your character control scripts and specifically its movement on the X and Z vectors. Make sure you use CharacterController methods for that movement such as Move() and SimpleMove(). If you are doing something crazy such as directly iterating the player’s position.x and position.z to move him about, then you’re not moving, you’re relocating (two vastly different things). There can be no physics applied on relocating objects.
If none of the solutions above solve your problem, you may be looking at a Unity glitch. Remake your player character, component-by-component. If that doesn’t solve it either, consider posting a bug on Unity’s site.
HI Diviner! Thanks! I think solution is the 4. This morning I’ll post the script that move my player!
I’m using something like
if (Input.GetKey (“W”)){
transform.Translate(Vector3.forward * Time.deltaTime);
}
And I have a system of dead reckoning too because tha game is on multiplayer!
I can exclude 1 2 3 because if I use the First Person Controller, everything work good!
This is the controller code:
var movementSpeed:float=0.02;
var syncDistanceThreshold:float = 0.1;
var speed:float=0.0;
var lastPosition = Vector3.zero;
var animationNames : Array = new Array("idle", "cammina");
var currentAnimation : int = 0;
function Update(){
speed = (transform.position - lastPosition).magnitude*100;
lastPosition = transform.position;
if(networkView.isMine){
if(speed!=0.0){
currentAnimation = 1;
}
if(speed==0.0){
currentAnimation = 0;
}
}
animation.CrossFade(animationNames[currentAnimation],0.2);
if(networkView.isMine){
if (Input.GetKey("w")){
transform.Translate (Vector3(0,0,3)*movementSpeed);
}
if (Input.GetKey("a")){
transform.Rotate (Vector3(0,-20,0)*Time.deltaTime*5);
}
if (Input.GetKey("d")){
transform.Rotate (Vector3(0,20,0)*Time.deltaTime*5);
}
}
}
function OnSerializeNetworkView(stream : BitStream, info : NetworkMessageInfo) {
if (stream.isWriting) {
///////////////////////////////////
var current : int;
current = currentAnimation;
stream.Serialize(current);
///////////////////////////////////////
var position = transform.position;
var rotation = transform.rotation;
stream.Serialize(movementSpeed);
stream.Serialize(position);
stream.Serialize(rotation);
}
else {
stream.Serialize(current);
currentAnimation = current;
position = Vector3.zero;
rotation = Quaternion.identity;
stream.Serialize(movementSpeed);
stream.Serialize(position);
stream.Serialize(rotation);
if (Vector3.Distance(position, transform.position) > syncDistanceThreshold) {
transform.position = position;
}
transform.rotation = rotation;
useNetworkInput = true;
}
}
may be the problem?
Yep, translations don’t calculate physics. Since you are already using a CharacterController Component, just change the Translate to Move or SimpleMove. It should work.
I have a suggestion in case you really don’t want to use the built-in move methods. If you attach a Rigidbody component on your player, you may trick Unity into using physics. It’s a long shot but try it nonetheless. If you do try to do it this way, add rigidbody.freezeRotation = true; and rigidbody.freezePosition = true; on your Start function of the Character Controller, so the movement is not affected by the Rigidbody’s physics.
Also, a bit of a nit-pick, I noticed that you don’t multiply by Time.deltaTime your translation. You may want to do that to make the movement frame rate independent.
Oh yes!!! thankyou Diviner!!! :) It work!!
can take advantage of your kindness for another little problem? (sorry for the english)
http://forum.unity3d.com/threads/107680-Singleton-Persistent-problem?p=712157#post712157