Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Tandrael · Jan 28, 2016 at 01:29 PM · c#movethird person controller

Move a Third Person Character via move-method

Hello,

I am working on a simple project where I move a character with external input. I want my character to move to a specified point. To keep it short I just imported the Standard Assets and used the Ethan-Model for that. I thought, it would make everything easier if I work with the given character controller etc. Here is my code so far:

 // move it
 public void MoveCharacterToPoint(Vector3 point)
 {
    // compute difference between current position and targeted position
    var offset = point - transform.position;
 
    // check if the distance is far enough
    if (offset.magnitude > 0.1f)
    {
        // normalize offset und multiply movement speed
        offset = offset.normalized * moveSpeed;
        Debug.Log("Move Character...");
 
        // issue move command
        m_Character.Move(offset, false, false);
 
        // move testobject
        testCylinder.transform.position = new Vector3 (x, y, z);
    }
 }

I am having trouble making my character move correctly with that code. Using this my character my character moves to the given point normally and then "dances" around the given point. It seems like Unity doesn't realise that my character reached the destination already.

I have also tried to multiply the offset with DeltaTime. In that case the character moves very, very slowly, almost not noticable, and an increase of the movement speed has no effect.

I would greatly apprediate hints on how to solve this.

Comment
Add comment · Show 2
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 brunocoimbra · Jan 28, 2016 at 02:30 PM 0
Share

If you want it to be a straight movement, you can then use Vector3.Lerp and change the t value over time.

avatar image Tandrael brunocoimbra · Jan 30, 2016 at 04:39 PM 0
Share

That works, but while using Vector3.Lerp the character has no movement animation at all. He just slides through the landscape. That is why I wanted to use move, which doesn't seem to work in this case.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by brunocoimbra · Feb 03, 2016 at 11:11 PM

Sorry, didn't noticed that you were dealing with animations (never used the ThirdPersonController until now).

Maybe not the best solution, but it does work. Create a new script and rename it to "MovePoint", then copy-paste the code below:

 using UnityEngine;
 
 public class MovePoint : MonoBehaviour
 {
     private static MovePoint point;
     private ThirdPersonCharacter character;
     private CapsuleCollider capsuleCollider;
 
     private void OnTriggerEnter(Collider collider)
     {
         if (collider.gameObject == character.gameObject)
         {
             character.Move(Vector3.zero, false, false);
             Destroy(point.gameObject);
             point = null;
         }
     }
 
     public static void CreatePoint(Vector3 position, ThirdPersonCharacter character)
     {
         if (point)
         {
             Destroy(point.gameObject);
             point = null;
         }
 
         point = new GameObject("MovePoint").AddComponent<MovePoint>();
         point.character = character;
         point.capsuleCollider = point.gameObject.AddComponent<CapsuleCollider>();
         point.capsuleCollider.isTrigger = true;
         point.capsuleCollider.radius = 0.1f;
         point.capsuleCollider.height = 10f;
     }
 }

And modify you method to that:

  public void MoveCharacterToPoint(Vector3 point)
  {
     // Before everything else:
     MovePoint.CreatePoint(point, m_Character);
     // Then do all your existing logic.
  }

Your character will need a collider attached to it, and a rigidbody too. If the rigidbody causes trouble to your movimentation, just set "isKinematic" to true.

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

c# script not doing anything. 2 Answers

Moving two objects and avoiding overlap with each other 1 Answer

Trying to fix my movement after the camera broke it. 0 Answers


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