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 /
This question was closed Jun 02, 2019 at 01:44 AM by DoctorChar for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by DoctorChar · Jun 01, 2019 at 02:06 PM · movementrigidbodyvelocityrigidbody.addforcex-axis

Add force lasting 1 frame (simple script)

I figured out the problem. If anyone else has this problem here is how to fix it. Make sure Apply root motion is turned off in your animator.

(Sorry, i wasn't clear with this post so ill try to be a little clearer. The velocity on the x axis is resting itself to 0 a single frame after I add the force. Even if I set in to Input.GetKey() the second i release the key all momentum on the x-axis stops.

Basically, the problem is that my velocity resets itself every frame on the X-axis.)

Hello again,

I recently asked a question very similar to this but I posted my full script. I decided to make a demo to see if the problem of my velocity only lasting one frame on the y axis would persist, and it did. here is the simple script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class SimpleTestMovement : MonoBehaviour {
     public Rigidbody mainrb;
     public float speed;
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
         print(mainrb.velocity);
         if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.D))
         {
             speed = 20 * (Input.GetKey(KeyCode.A) || Input.GetKeyDown(KeyCode.A) ? -1 : 1);
             mainrb.AddForce(new Vector3(speed, speed, 0), ForceMode.Impulse);
         }
         
     }
 }

This is the entire script which means that there must be something wrong in the editor. My player had a capsule collider and a rigidbody attached, the rigidbody has no freezes on position and the capsule collider does not have a physics material that could be messing something up. This is only happening in the x axis, the y axis works as it should. If anyone knows anything I could try I would appreciate a point in the right direction. Thanks!

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 highpockets · Jun 02, 2019 at 01:42 AM 0
Share

It should not completely slow down on the next frame, but that depends on your settings. What is the mass of the rigidbody? what is the speed variable set too? What is drag set to?? All this will have to be taken into account. Try applying more force and changing the force mode for example to see where the difference lies if any.

1 Reply

  • Sort: 
avatar image
0

Answer by NoCandyIncluded · Jun 01, 2019 at 03:03 PM

On line 16, Input.GetKeyDown() gets when the key is pressed, so everything in that code will only execute during the frame that you pressed the button. If you want the code to be executed during the whole time your pressing your key down, try, Input.GetKey()

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 DoctorChar · Jun 02, 2019 at 01:16 AM 0
Share

Sorry, i wasn't clear with this post so ill try to be a little clearer. The velocity on the x axis is resting itself to 0 a single frame after I add the force. Even if I set in to Input.Get$$anonymous$$ey() the second i release the key all momentum on the x-axis stops.

Basically, the problem is that my velocity resets itself every frame on the X-axis.

Follow this Question

Answers Answers and Comments

193 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

Related Questions

Ball moving in a tube 0 Answers

Glitch when erasing rigidbody's velocity to "calculate" new 0 Answers

Vector3 position changing without force being applied in the direction 1 Answer

Player movement controls too slow 1 Answer

My accelerate script ramps up in the inspector but no movement. 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