- Home /
Question by
diferte · Jun 12, 2012 at 09:33 PM ·
character controllerstuck
Character stuck climbing
Hi there... My player walk in a 2d game... when walk to right is fine, but when do a climb do a stuck.
There is my code:
function Update() { var movement = Vector3.zero; movement = character.transform.right forwardSpeed velocityPLayer;
// Check for jum![alt text][1]p
if ( character.isGrounded )
{
var jump = false;
var touchPad = jumpTouchPad;
_HeroeMovs.walk();
inAirMultiplier = 1.4;
if ( !touchPad.IsFingerDown() )
canJump = true;
if ( canJump && touchPad.IsFingerDown() )
{
jump = true;
canJump = false;
}
#if UNITY_EDITOR
if(Input.GetKey("a"))
{
jump = true;
canJump = false;
}
#endif
if ( jump )
{
inAirMultiplier = 0.2;
_HeroeMovs.jump();
// Apply the current movement to launch velocity
velocity = character.velocity;
velocity.y = jumpSpeed;
}
}
else
{
//velocity.y += Physics.gravity.y * Time.deltaTime;
velocity.y += Physics.gravity.y * 0.08;
// Adjust additional movement while in-air
movement.x *= inAirMultiplier;
}
movement += velocity;
movement += Physics.gravity;
movement *= Time.deltaTime;
// Actually move the character
character.Move( movement );
if ( character.isGrounded )
// Remove any persistent velocity after landing
velocity = Vector3.zero;
}
[1]: http://answers.unity3d.com/storage/temp/1233-stuck.jpg
stuck.jpg
(34.7 kB)
Comment
So this occurs when you just walk? Because you included the jump stuff and I'm not sure it's because you tried to "climb" the incline by jumping up it and got stuck. Also, I'd like you to try just setting a static number for the "movement" variable, to see if its just because you're losing too much velocity on collision with the slope.
This occurs only when the player walk the incline....Jumping the incline works fine.