• 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 MKamen · Jul 01, 2017 at 07:32 AM · scripting beginneranimation controller

I need example for script (3D, 4 legged character)

Hello guys! My child is doing school project in Unity and she asked me to help her with this one. She created landscape and imported prefabricated free horse from Unity store (yes, it's project which includes horse riding, but without human, horse is character). She imported this horse: https://www.assetstore.unity3d.com/en/#!/content/16687 , but as I can see, it doesn't come with scripts for controlling and changing animation regarding pressed key (idle, walk, run). We both are struggling with First Person and Third Person Controller but not satisfied with results. Can someone help us with some basic control script which includes moving (forward, backward, left, right and jump) and how to activate different animation when other key is pressed. Thanks in advance.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by FlaSh-G · Jul 01, 2017 at 09:38 AM

Quadrupeds, as four-legged characters are called (might help with searching for future problems), don't have any support in the standard assets for all i know. Doing a quick search, I didn't find any useful ready-to-go packages either.

It seems that you need to either settle with poor collision geometry by using the biped solutions or bite the bullet and code your own.

The latter would probably require a rigidbody, a mesh collider or compound collider, and at least one script for the movement.

Edit: Oh, I just saw you were already going for a script in the question's title... let me write somewthing quick:

 [RequireComponent(typeof(Rigidbody))]
 class QuadrupedMovement : MonoBehaviour
 {
   private Rigidbody rb;
   public float speed = 5;
   public float rotateSpeed = 5;
 
   private void Awake()
   {
     rb = GetComponent<Rigidbody>();
   }
 
   private void FixedUpdate()
   {
     var input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
     input = Vector3.ClampMagnitude(input, 1);
 
     var direction = transform.forward;
     direction.y = 0; // just in case
     direction = Quaternion.Euler(0, Input.GetAxis("Mouse X") * rotateSpeed , 0) * direction;
     var newRotation = Quaternion.Euler(direction);
     rb.MoveRotation(newRotation);
 
     rb.velocity = transform.TransformDirection(input) * speed;
   }
 }

I haven't tested this code yet, but I guess it conveys the general idea. This is, of course, just one of many ways to attempt this. Here, mouse movement rotates the character while WASD / Arrow Keys move forwards, backwards, and strafe.

For the setup: this article has an example for a possible mesh collider: Mesh Collider A horizontal CapsuleCollider might work as well.

Make sure to freeze X and Z axes with the rigidbody's rotation constraints. For smooth rotation, slap this script of mine onto the object as well and leave the rigidbody's Interpolation setting on "None". Mind the scripts comment by the way.

Hope this helps.

Comment
Add comment · Show 3 · 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
avatar image MKamen · Jul 03, 2017 at 07:35 AM 0
Share

@FlaSh-G

Script is now without errors. I have RigidBody with rotation constraints. When I attach script to character, nothing happened - it just stands still and doesn't respond to commands. I thought it has something to do with character so I inserted regular cube and attached the script but cube didn't move also. What I do wrong?

avatar image FlaSh-G · Jul 03, 2017 at 10:57 AM 0
Share

Did you put my linked script (FixedUpdateInterpolator.cs) on the object? If yes, did you follow the instruction in its comment?

avatar image MKamen FlaSh-G · Jul 04, 2017 at 11:30 AM 0
Share

It's working. Thanks.

avatar image
0

Answer by MKamen · Jul 01, 2017 at 12:24 PM

@FlaSh-G

Thanks for the script! However, there's an error in code:

direction = Quaternion.Euler(0, Input.GetAxis("Mouse X") rotateSpeed , 0);

It says: error CS0019: Operator *=' cannot be applied to operands of type UnityEngine.Vector3' and `UnityEngine.Quaternion'

Comment
Add comment · Show 1 · 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
avatar image FlaSh-G · Jul 01, 2017 at 01:39 PM 0
Share

Try to add comments to answers as comments to answers ins$$anonymous$$d of answers to the question ;)

I changed that line.

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

70 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

flipping animation (I know this is asked alot) 0 Answers

Inherting Monobehavior and another Class 0 Answers

Accessing variable from parent 1 Answer

Standard assets MouseLook.cs script question 0 Answers

Using singleton & DontDestroyOnLoad to keep a menus state. 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