Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by cloud107 · Mar 14, 2012 at 02:15 AM · scriptingbasicsanimation problem

Plsss help :( plsss

when i walk there is no problem, when i run it stops in a sec. and continue to run, when i jump the animation of walk and run stops :( plsss help

http://www.youtube.com/watch?v=FBctCSmQPaw&feature=youtu.be

and here are my screenshot that I'm using for my script. http://imageshack.us/photo/my-images/685/helpc.jpg/

![http://imageshack.us/photo/my-images/685/helpc.jpg/][3]alt text!

125*that is my thirpersonContoller Script*125

 private var controller : CharacterController; 

 

function Start ()

{

 controller = GetComponent(CharacterController); 

 animation.wrapMode = WrapMode.Loop;

 

 animation["jump"].layer = 10;

 animation["jump"].wrapMode = WrapMode.ClampForever;

 

 animation["fall"].layer = 10;

 animation["fall"].wrapMode = WrapMode.ClampForever;

 

 animation["land"].layer = 10;

 animation["land"].wrapMode = WrapMode.Once;

 

 animation.Stop();

 animation.Play("idle");

}

function Update ()

{

 var MovementY = controller.velocity.y;

 var controller : CharacterController =  GetComponent(CharacterController);

 

 if ((MovementY > 0.1) && !(controller.collisionFlags & CollisionFlags.Below))

 {

 animation.CrossFade("jump");

 }

 else if ((MovementY < -5) && !(controller.collisionFlags & CollisionFlags.Below))

 {

 animation.CrossFade("fall");

 }

 

 if ( ((animation.IsPlaying("jump")) || (animation.IsPlaying("fall"))) && (controller.collisionFlags & CollisionFlags.Below))

 animation.CrossFade("land");

 

 if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.2)

   animation.CrossFade("run");

 else

   animation.CrossFade("idle");        

}

125*This is my ThirdPerson Camera*125

var cameraTransform : Transform; private var _target : Transform;

// The distance in the x-z plane to the target

var distance = 7.0;

// the height we want the camera to be above the target var height = 3.0;

var angularSmoothLag = 0.3; var angularMaxSpeed = 15.0;

var heightSmoothLag = 0.3;

var snapSmoothLag = 0.2; var snapMaxSpeed = 720.0;

var clampHeadPositionScreenSpace = 0.75;

var lockCameraTimeout = 0.2;

private var headOffset = Vector3.zero; private var centerOffset = Vector3.zero;

private var heightVelocity = 0.0; private var angleVelocity = 0.0; private var snap = false; private var controller : ThirdPersonController; private var targetHeight = 100000.0;

function Awake () { if(!cameraTransform && Camera.main) cameraTransform = Camera.main.transform; if(!cameraTransform) { Debug.Log("Please assign a camera to the ThirdPersonCamera script."); enabled = false;
}

 _target = transform;
 if (_target)
 {
     controller = _target.GetComponent(ThirdPersonController);
 }
 
 if (controller)
 {
     var characterController : CharacterController = _target.collider;
     centerOffset = characterController.bounds.center - _target.position;
     headOffset = centerOffset;
     headOffset.y = characterController.bounds.max.y - _target.position.y;
 }
 else
     Debug.Log("Please assign a target to the camera that has a ThirdPersonController script attached.");

 
 Cut(_target, centerOffset);

}

function DebugDrawStuff () { Debug.DrawLine(_target.position, _target.position + headOffset);

}

function AngleDistance (a : float, b : float) { a = Mathf.Repeat(a, 360); b = Mathf.Repeat(b, 360);

 return Mathf.Abs(b - a);

}

function Apply (dummyTarget : Transform, dummyCenter : Vector3) { // Early out if we don't have a target if (!controller) return;

 var targetCenter = _target.position + centerOffset;
 var targetHead = _target.position + headOffset;

// DebugDrawStuff();

 // Calculate the current & target rotation angles
 var originalTargetAngle = _target.eulerAngles.y;
 var currentAngle = cameraTransform.eulerAngles.y;

 // Adjust real target angle when camera is locked
 var targetAngle = originalTargetAngle; 
 
 // When pressing Fire2 (alt) the camera will snap to the target direction real quick.
 // It will stop snapping when it reaches the target
 if (Input.GetButton("Fire2"))
     snap = true;
 
 if (snap)
 {
     // We are close to the target, so we can stop snapping now!
     if (AngleDistance (currentAngle, originalTargetAngle) < 3.0)
         snap = false;
     
     currentAngle = Mathf.SmoothDampAngle(currentAngle, targetAngle, angleVelocity, snapSmoothLag, snapMaxSpeed);
 }
 // Normal camera motion
 else
 {
     if (controller.GetLockCameraTimer () < lockCameraTimeout)
     {
         targetAngle = currentAngle;
     }

     // Lock the camera when moving backwards!
     // * It is really confusing to do 180 degree spins when turning around.
     if (AngleDistance (currentAngle, targetAngle) > 160 && controller.IsMovingBackwards ())
         targetAngle += 180;

     currentAngle = Mathf.SmoothDampAngle(currentAngle, targetAngle, angleVelocity, angularSmoothLag, angularMaxSpeed);
 }


 // When jumping don't move camera upwards but only down!
 if (controller.IsJumping ())
 {
     // We'd be moving the camera upwards, do that only if it's really high
     var newTargetHeight = targetCenter.y + height;
     if (newTargetHeight < targetHeight || newTargetHeight - targetHeight > 5)
         targetHeight = targetCenter.y + height;
 }
 // When walking always update the target height
 else
 {
     targetHeight = targetCenter.y + height;
 }

 // Damp the height
 var currentHeight = cameraTransform.position.y;
 currentHeight = Mathf.SmoothDamp (currentHeight, targetHeight, heightVelocity, heightSmoothLag);

 // Convert the angle into a rotation, by which we then reposition the camera
 var currentRotation = Quaternion.Euler (0, currentAngle, 0);
 
 // Set the position of the camera on the x-z plane to:
 // distance meters behind the target
 cameraTransform.position = targetCenter;
 cameraTransform.position += currentRotation * Vector3.back * distance;

 // Set the height of the camera
 cameraTransform.position.y = currentHeight;
 
 // Always look at the target    
 SetUpRotation(targetCenter, targetHead);

}

function LateUpdate () { Apply (transform, Vector3.zero); }

function Cut (dummyTarget : Transform, dummyCenter : Vector3) { var oldHeightSmooth = heightSmoothLag; var oldSnapMaxSpeed = snapMaxSpeed; var oldSnapSmooth = snapSmoothLag;

 snapMaxSpeed = 10000;
 snapSmoothLag = 0.001;
 heightSmoothLag = 0.001;
 
 snap = true;
 Apply (transform, Vector3.zero);
 
 heightSmoothLag = oldHeightSmooth;
 snapMaxSpeed = oldSnapMaxSpeed;
 snapSmoothLag = oldSnapSmooth;

}

function SetUpRotation (centerPos : Vector3, headPos : Vector3) { // Now it's getting hairy. The devil is in the details here, the big issue is jumping of course. // When jumping up and down we don't want to center the guy in screen space. // This is important to give a feel for how high you jump and avoiding large camera movements. //
//
At the same time we dont want him to ever go out of screen and we want all rotations to be totally smooth. // // So here is what we will do: // // 1. We first find the rotation around the y axis. Thus he is always centered on the y-axis // 2. When grounded we make him be centered // 3. When jumping we keep the camera rotation but rotate the camera to get him back into view if his head is above some threshold // 4. When landing we smoothly interpolate towards centering him on screen var cameraPos = cameraTransform.position; var offsetToCenter = centerPos - cameraPos;

 // Generate base rotation only around y-axis
 var yRotation = Quaternion.LookRotation(Vector3(offsetToCenter.x, 0, offsetToCenter.z));

 var relativeOffset = Vector3.forward * distance + Vector3.down * height;
 cameraTransform.rotation = yRotation * Quaternion.LookRotation(relativeOffset);

 // Calculate the projected center position and top position in world space
 var centerRay = cameraTransform.camera.ViewportPointToRay(Vector3(.5, 0.5, 1));
 var topRay = cameraTransform.camera.ViewportPointToRay(Vector3(.5, clampHeadPositionScreenSpace, 1));

 var centerRayPos = centerRay.GetPoint(distance);
 var topRayPos = topRay.GetPoint(distance);
 
 var centerToTopAngle = Vector3.Angle(centerRay.direction, topRay.direction);
 
 var heightToAngle = centerToTopAngle / (centerRayPos.y - topRayPos.y);

 var extraLookAngle = heightToAngle * (centerRayPos.y - centerPos.y);
 if (extraLookAngle < centerToTopAngle)
 {
     extraLookAngle = 0;
 }
 else
 {
     extraLookAngle = extraLookAngle - centerToTopAngle;
     cameraTransform.rotation *= Quaternion.Euler(-extraLookAngle, 0, 0);
 }

}

function GetCenterOffset () { return centerOffset; }

And this is my animationscript private var controller : CharacterController;

function Start ()

{

 controller = GetComponent(CharacterController); 

 animation.wrapMode = WrapMode.Loop;

 

 animation["jump"].layer = 10;

 animation["jump"].wrapMode = WrapMode.ClampForever;

 

 animation["fall"].layer = 10;

 animation["fall"].wrapMode = WrapMode.ClampForever;

 

 animation["land"].layer = 10;

 animation["land"].wrapMode = WrapMode.Once;

 

 animation.Stop();

 animation.Play("idle");

}

function Update ()

{

 var MovementY = controller.velocity.y;

 var controller : CharacterController =  GetComponent(CharacterController);

 

 if ((MovementY > 0.1) && !(controller.collisionFlags & CollisionFlags.Below))

 {

 animation.CrossFade("jump");

 }

 else if ((MovementY < -5) && !(controller.collisionFlags & CollisionFlags.Below))

 {

 animation.CrossFade("fall");

 }

 

 if ( ((animation.IsPlaying("jump")) || (animation.IsPlaying("fall"))) && (controller.collisionFlags & CollisionFlags.Below))

 animation.CrossFade("land");

 

 if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.2)

   animation.CrossFade("run");

 else

   animation.CrossFade("idle");        

}

PLSSS help :(

Comment
Add comment · Show 18
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · Mar 14, 2012 at 02:18 AM 1
Share

Please spell Please correctly. This isn't a text message. You should use question names that are actually relevant to your problem- 'Please help' doesn't give us any information at all about what your problem might be.

Also, you shouldn't post an entire page of badly-formatted code and expect people to read it all. You should post only the parts that you think are relevant, and edit it later to include more if it turns out that it isn't enough. I don't want to read your entire script to find one simple problem.

avatar image GC1983 · Mar 14, 2012 at 02:33 AM 0
Share

This is a ton of code for just a run/jump animation. All of the camera code is unnecessary to know what your issue may possibly be. It could be something with your animations or how youre calling them. Seems youre over-complicating things. Try just using physics; call an AddForce() and adjust the gravity appropriately.

avatar image cloud107 · Mar 14, 2012 at 03:11 AM 0
Share

i will give you guys this project and fix? can you guyz do that? plsss help me :(

avatar image syclamoth · Mar 14, 2012 at 03:13 AM 0
Share

Only if you pay me. I won't just take your project and magically solve all your problems for nothing.

avatar image GC1983 · Mar 14, 2012 at 03:36 AM 1
Share

Lol begging people to fix your issues wont help you learn how to do it. Try breaking down what you have and find where your issue could possibly be and get back to us. I recommend putting your camera on its own script. And use your controller script to settle all the animations between your keystrokes/mouse clicks. You dont need to reference controller : CharacterController twice and especially in the Update(). That actually can create memory leaking and is bad from. You can call it globally or on Awake() Start().

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Finding center of a cube 1 Answer

Script that switches between first and third person controller 3 Answers

auto detect resolution 1 Answer

Calling a script from other GameObject after finding it using OverlapSphere 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges