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 SuperRaed · Sep 17, 2016 at 03:37 PM · movementtransform.positionaccelerationsmoothing

how to add a drag/resistance effect to my character's movement

I want to move my character left and right if Input.getKey(left/right arrow) but instead of the usual way transform.position+=Vector3.Right*Speed*Time.deltaTImewhere the character would move with a constant speed ex. from 0 to 3 when Key pressed and from 3 to 0 suddenly when keyUp . instead I want to gradually reach a max speed within a frame of Time when Key pressed and gradually back to zero when Key is Up. alt text

keyup.png (11.1 kB)
Comment
Add comment · Show 1
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 Sergio7888 · Sep 17, 2016 at 06:45 PM 0
Share

try use drag property of rigidbody

2 Replies

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

Answer by yasser_kaddoura · Sep 17, 2016 at 04:33 PM

I guess this is what you are looking for:

 horizontal = Input.GetAxis("Horizontal");

 myRb.velocity = new Vector2(horizontal * speed, myRb.velocity.y);





Comment
Add comment · Show 4 · 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 SuperRaed · Sep 17, 2016 at 05:46 PM 0
Share

hey @yasser_kaddoura, I think this may work, but I'm afraid it's too steep for my purpose, that is the horizontalAxis goes from 0-1very fast so the dragging effect is $$anonymous$$imized, can I adjust the sensitivity of the axis?

avatar image SuperRaed · Sep 17, 2016 at 05:50 PM 0
Share

also it seems to me as though the value of horizontalAxis abruptly change to zero when $$anonymous$$ey is up ele$$anonymous$$ating the slide movement at the end, am I correct?

avatar image Bunny83 SuperRaed · Sep 17, 2016 at 06:34 PM 2
Share

Check the input manager (Edit -> Project Settings -> Input) and change the behaviour the way you like. The "sensitivity" value controls how fast the value goes from 0 to 1 when the button is pressed. The "gravity" value controls how fast it returns to 0. You also might want to unckeck "snap" which does exactly what you don't want: When you press the opposite direction it snaps to 0 ans start "growing" in the opposite direction.

avatar image SuperRaed Bunny83 · Sep 19, 2016 at 04:35 PM 0
Share

thanks alot @Bunny83 :) it's exactly what I wanted

avatar image
0

Answer by SorenaCoder · Sep 17, 2016 at 07:46 PM

Hi, First :

 var horizontal = Input.GetAxis("Horizontal") * speed;
 var vertical = Input.GetAxis("Vertical") * speed;
 
 rigidbodyComponent.velocity += new Vector3(horizontal,vertical);

and in second step:

 rigidbodyComponent.velocity = Vector3.ClampMagnitude(rigidbodyComponent.velocity,maximumSpeed);

Have fun

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

66 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

Related Questions

Networked position interpolation implementation (not Dead Reckoning)? 1 Answer

Standard FPS Controller - Smoothing Movement 2 Answers

Character Motor: standard vs. custom ? 0 Answers

How to Tilt a Spaceship Based on Inertia/Acceleration Force Separate from Facing Direction? 2 Answers

How to move an object smoothly while in a Coroutine / Ienumerator? 3 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