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 /
  • Help Room /
avatar image
0
Question by RemDust · Sep 30, 2015 at 02:02 PM · movementrigidbody2dvelocityaddforce

2D : How to overwrite rigidbody velocity when "skill" input pressed ???

Hi guys, I'm having a hard time figure it out. I'm moving my character by setting is rigidbody.velocity like this :

     void Update () {

     var right = inputState.GetButtonValue (inputButtons [0]);
     var left = inputState.GetButtonValue (inputButtons [1]);
     if ((right || left)&& !esquive) {
         var tmpSpeed = speed;
         var VelX = tmpSpeed * (float)inputState.direction;
         body2d.velocity = new Vector2 (VelX, body2d.velocity.y);
     }

Now, this is all fine but when I try to change it with magic or skill uses, understand when another behavior script is triggered, there seem to have a conflict between the different body.velocity requests and my player just keep on walking...

For instance a simple "forward dash" like

      void OnEnable()
 {
     body = GetComponentInParent<Rigidbody2D> ();
     body.velocity = new Vector2 (500, 20);
 }

only works if i'm not trying to walk at the same time... I don't know how to easily fix it, I'm thinking about toggling the inputmanager during the dash but it seems so overworked ^^ Any help would be really appreciated :)

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 meat5000 ♦ · Sep 30, 2015 at 02:14 PM 0
Share

Are you saying you use a separate script for each movement function? I wouldn't say this is advisable.

avatar image RemDust meat5000 ♦ · Sep 30, 2015 at 02:42 PM 0
Share

The first one is for simple movement (walking as usual) and I'm working on a "skill system" : when player gets a new skill, the skill gameobject become a child of player, and by enabling it (with the skill key), the behavior is triggered. it's working great for a lot of stuff so far, I don't really see why the skill couldn't be on a separate script.

avatar image meat5000 ♦ RemDust · Sep 30, 2015 at 02:55 PM 0
Share

And this happens everytime you activate a skill? Sounds like a lot of work for you and the program.

Personally I'd believe that the overuse of OnEnable will eventually result in something going wrong.

I'm trying to see where in the script the behaviours become 'overridden'. You may set the velocity separately but wont the value simply revert on every update?

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Using rb.velocity and Add Force on the same gameobject? 0 Answers

Terminal velocity on x and y axis is higher than normal when force is applied to both axis simultaneously. 0 Answers

How to properly move a rigidbody character? 0 Answers

[2D] Can't AddForce to x but y works fine. 1 Answer

RigidBody2D.AddForce() horizontally is not working! 2 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