• 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 Khale06 · Sep 28, 2013 at 07:31 PM · untiy

Movement on uneven terrain

Hi all:

I've got a problem regarding moving my character on uneven terrain. I researched for a solution and found out the itween extension has such features. I already tried it, problem is it aint working correctly, everytime I click the character stutters up and down the y axis, but it still moves to the position where I clicked it at fast speeds. I temporarily crossed out itween in my list of solutions after that. I have a code here for my movement:

 void MoveTo() //function for moving
     {
         if(canMove)
         {
             Vector3 dir = targetPosition - transform.position;
             float dist = dir.magnitude;        
             float move = speed * Time.deltaTime;
             if(dist > move)
             {                
                 cc.Move(dir.normalized * move);                    
                 //Debug.Log(transform.position+" VS " + targetPosition);
             } 
             else
             {                
                 cc.Move(dir);    
                 anim.SetFloat(hash.moveSpeedFloat, 0f);  // sets the speed variable in the animator                
             }       
         //Rotation Smooth
         transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.deltaTime * rotateSpeed);            
         }                
     }

The "cc" in the code is the name for my character controller. This script works fine with flat terrain (all animations works correctly, from locomotion to idle and vice versa) and also collides with other objects in scene. SO basically my goal is to make my character move through uneven terrain and stop (with corresponding animations also to stop) at a given point and also stop the animation where I clicked.

Any input would be helpful, Thanks in advance.

PS: Im using my own character model with bones and used unity's mecanim to animate the character with the rawcap motion asset.

Comment
Add comment
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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

15 People are following this question.

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

Related Questions

how to get in game numerical input 1 Answer

Unity 3d CPU Usage on a Macbook Pro 3 Answers

how to show data in same gui layout..?? 1 Answer

All my game is gone 2 Answers

How to Avoid Corner paths in A* pathfinding 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges