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 TivoltGames · Jan 13, 2015 at 07:23 PM · animationcharactermovingimporting

Problem with moving an imported animation

Hello! :) It's my first post here so I hope I'll do good :P

I have a pretty simple task to do for my college class - a game, that I figured out be a simple third person platformer with a cat as a main character. Currently I'm having a big problem with moving my cat the right way. This is how a part of my CatMovement script looks like:

 void FixedUpdate () {
 
            walkSpeed = Input.GetAxis ("Vertical");
         turnSpeed = Input.GetAxis ("Horizontal");
         if (walkSpeed < 0) 
         {
             transform.Translate (0, 0, 0);
         } 
         else 
         {
             transform.Translate (0, 0, walkSpeed * 0.1f);
         }
         transform.Rotate (0, turnSpeed, 0);
         if(!Input.GetKey("left") && !Input.GetKey("right"))
         {
             action = false;
             animator.SetBool ("akcja", action);
         }
         else{
             action = true;
             animator.SetBool ("akcja", action);
         }
         animator.SetFloat ("chodzenie", walkSpeed);
         animator.SetFloat ("obrot", turnSpeed);
         if (transform.position.y < -2)
         {
             Die ();
         }
     }


It's able to rotate at a slow speed, but whenever I click W or UP arrow - instead of going forward it goes to the right. In the FixedUpdate script I'm also changing values for an Animator, cause I want the walking animation to run then the speed goes up.

Can anyone suggest me what can I do about it? Maybe a different way to steer the cat? I tried using RigidBody, but whenever I start the game - the cat disappears. I tried exporting my cat model in a few different ways from 3ds MAX but nothing works. I've read the tip about creating an EmptyObj to be the parent of an imported object, but I don't really know how would it work with an animation, mostly because I have to move the character (I want it to be third-person, so the cat in moving in the direction it's facing.) and animate it. Maybe writing a script for the EmptyObj just for the movement, and a script for the cat to change the animator values, check for collisions etc?

Any help would be appreciated. And also sorry if my english isn't that good, it's not my native language ;)

Comment
Add comment · Show 3
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 bodec · Jan 13, 2015 at 07:27 PM 0
Share

try transform.forward walksspeed time.deltatime; on line 11

avatar image TivoltGames · Jan 13, 2015 at 07:37 PM 0
Share

try transform.forward walksspeed time.deltatime; on line 11

Sorry, can you be more specific? :/ I'm pretty new to unity...

avatar image bodec · Jan 13, 2015 at 09:51 PM 0
Share

online 11 replace your line with

 transform.forward * speed*time.deltatimr

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Mondkin · Jan 14, 2015 at 03:40 AM

There are two things to change:

Rotation:

When you execute this line in your FixedUpdate() it is being called a lot of times while you press your key:

 transform.Rotate (0, turnSpeed, 0);

So, in case you want to rotate your character in increments do this, which will rotate exactly turnSpeed each second you have your key pressed:

 transform.Rotate (0, turnSpeed * Time.deltaTime, 0);

But if what you want is to turn your character to one way or another do this instead:

 transform.rotation = Quaternion.AngleAxis(90, rotationAxis);

That will turn your character exactly 90 degrees, no matter how many times it is called.

Translation:

Do not move your player like this as it will ignore all physics calculations along the way:

 transform.Translate (0, 0, walkSpeed * 0.1f);

Instead do it like this:

 Rigidbody2D rigidBodyPlayer = GetComponent<Rigidbody2D> ();
 Vector3 movement = new Vector3(0, 0, walkSpeed * Time.deltaTime);
 rigidBodyPlayer.MovePosition (transform.position + movement);

If you are using 3D physics then use Rigidbody instead of Rigidbody2D.

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

Character fingers get distorted when imported in Unity 1 Answer

Importing Character and Animations 2 Answers

Character Importing Issue Blender 1 Answer

How to handle multiple animation variants 1 Answer

import softimage mod tool 7.5 to unity, good or not? 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