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 /
This question was closed Apr 16, 2019 at 11:48 PM by leviathan20054 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by leviathan20054 · Apr 18, 2019 at 08:09 AM · movementforcecube

why is my my movement not working?,why does my addforce only last for a split second?

im very new to coding so sry if this is a simple mistake.

ive set up my cube to move in any direction but for some reason whenever i press a button to move i move in the direction i pressed but only for a split second even if i hold the key down. here is my script

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class ri : MonoBehaviour {

 private Rigidbody rb;
 public int speed;
 public int hspeed;

 // Start is called before the first frame update
 void Start()
 {
     rb = GetComponent<Rigidbody>();
 }

 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown("w"))
     {
         rb.AddForce(0, 0, speed);


     }
     if (Input.GetKeyDown("s"))
     {
         rb.AddForce(0, 0, -speed);


     }
     if (Input.GetKeyDown("a"))
     {
         rb.AddForce(hspeed, 0, 0);


     }
     if (Input.GetKeyDown("d"))
     {
         rb.AddForce(-hspeed, 0, 0);


     }
 }

} ,im very new to coding and am trying to get a block to move around and ive set it up so that it can move in any direction but whenever i press the key to move in that direction the cube moves for like half a second then stops. the only way to move it is to key pressing the key. here is my code.

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class ri : MonoBehaviour {

 private Rigidbody rb;
 public int speed;
 public int hspeed;

 // Start is called before the first frame update
 void Start()
 {
     rb = GetComponent<Rigidbody>();
 }

 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown("w"))
     {
         rb.AddForce(0, 0, speed);


     }
     if (Input.GetKeyDown("s"))
     {
         rb.AddForce(0, 0, -speed);


     }
     if (Input.GetKeyDown("a"))
     {
         rb.AddForce(hspeed, 0, 0);


     }
     if (Input.GetKeyDown("d"))
     {
         rb.AddForce(-hspeed, 0, 0);


     }
 }

}

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 leviathan20054 · Apr 16, 2019 at 11:36 PM 0
Share

wtf idk why my question doubled up.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

224 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

Related Questions

Roll-a-Ball: Ball moves upwards or downwards by itself. 0 Answers

There is a way to set a max to the resultant force in a object ? 1 Answer

I am interested in moving a ragdoll character only using Forces. 0 Answers

Cube movement 0 Answers

Making Force Grip/Grab 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