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 LORDsereius · Jan 09, 2019 at 01:49 PM · scripting problemmovementanimator

Having problem with detecting movement

Hey there everybody :D so I have a problem with this code.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class AnimationPlay : MonoBehaviour {
     private Animator animator;
     private Vector3 oldPos,newPos;
     void Start()
     {
         oldPos = GameObject.Find ("FPSController").transform.position;
         animator = gameObject.GetComponent<Animator> ();
     }
     void Update () 
     {
         newPos = GameObject.Find ("FPSController").transform.position;
         if (newPos != oldPos)
         {
             animator.SetBool ("Moving", true);
         }
         else if (newPos == oldPos)
         {
             animator.SetBool ("Moving", false);
         }
         oldPos = GameObject.Find ("FPSController").transform.position;
     }
 }
 

I'm trying to detect if the game object "FPSController" is moving by using transform.position and see if it's position has changed from the last time and if it is moving, I will set the Boolean "Moving" true which I created in an animator for game object "Player" (("Player" is a child of "FPSController")) and then it should play walking animation that i made in blender. when my character moves, the Boolean keeps flickering true and false and also the walking animation gets too long to play like 6 or 7 seconds after player moves. I have no idea what is causing this, cuz in theory it should work... alt text in the picture "FPSController" is moving, the "Moving" Boolean is flickering, and the Standing animation is playing instead of walking animatin...

am i missing something? and thanks for your time :)

untitled.png (284.1 kB)
Comment
Add comment · Show 7
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 HCIC · Jan 09, 2019 at 02:19 PM 0
Share

You could use the difference between the two states and then magnitude it to get the velocity. You can then set the walking animation while the velocity is greater than a threshold (eg 0.05). But it is a bit of a hack. Why dont you directly trigger the animation from within the FPSController?

avatar image LORDsereius HCIC · Jan 09, 2019 at 02:22 PM 0
Share

i tried using the velocity and it didn't change the result and about triggering the animation in FPScontroller, you mean like animator.play()?!

avatar image Klarzahs LORDsereius · Jan 09, 2019 at 02:44 PM 0
Share

Similar to your "$$anonymous$$oving" boolean you can create a Trigger. Then you can assign this trigger as a transition condition from Standing to Walking. You force this transition by calling Animation.SetTrigger() in the FPSController, e.g. directly when you apply force/motion to your character.

Show more comments
avatar image aardappel156 · Jan 10, 2019 at 12:57 PM 0
Share

Try turning off "has exist time"

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Spacejet13 · Jan 23, 2019 at 01:35 AM

Use the same bool variables you have used to determine whether the character is moving (if player is pressing the 'move' button) and making him move in the game. Just set the animation to change if player presses the button that moves the character.

.

EDIT:

Your animation is not transitioning!! look in the inspector window of the image you posted. the standing and walking animations should not overlap each other! it should transition from standing to walking

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

228 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 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 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 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

2 problems with new animation / animator,2 problems with animation 0 Answers

2D Movement and getting the mouse position 0 Answers

Simple Animation and Scripting Problem. 1 Answer

How to Add Knockback Force Based on What Rotation it Came From 2 Answers

I can't get any type of joystick to move my player 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