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
1
Question by UltOCreatE · Jan 02, 2018 at 12:53 AM · 2d-platformermovement script

Unity 2D Movement Script

My script in MonoDevelop seems to have no problems with no errors or warnings are displayed, but when I run the game and try to move my character, there is no movement. I see nothing wrong with the script or input and I am having issues troubleshooting the problem. If it is a simple mistake it is only because I am only beginning to use Unity. Link to file: https://drive.google.com/file/d/1Jh_JKPGwWWMzmmysRTEX4MjJ_pLeUmJc/view

Comment
Add comment · Show 5
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 David_Rios · Jan 02, 2018 at 03:54 AM 0
Share

The file you've provided isn't enough to get anything from. You have to copy the entire project folder rather than copying the .unity scene file. If the script isn't doing anything, maybe it isn't attached, maybe it isn't referencing the player correctly. There are various causes for this.

avatar image Ginxx009 David_Rios · Jan 02, 2018 at 03:58 AM 0
Share

I Agree with BDCakeRules maybe it isn't attached?

avatar image Tespy · Jan 02, 2018 at 04:05 AM 1
Share

You've accidentally uploaded the scene file ins$$anonymous$$d of the script ^^; Could you just show the relevant code in your question?

avatar image UltOCreatE Tespy · Jan 02, 2018 at 07:03 PM 0
Share

https://drive.google.com/open?id=1Jh_J$$anonymous$$PGwWW$$anonymous$$zmmysRTEX4$$anonymous$$jJ_pLeUmJc

avatar image UltOCreatE Tespy · Jan 03, 2018 at 01:11 AM 0
Share

I have used many different scripts and one or two of them have worked, but it is no the type of movement I want, some glide too much and is not responsive and some do not have jump movement, the rest don't work.

3 Replies

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

Answer by tormentoarmagedoom · Jan 03, 2018 at 01:46 AM

use something like this in the Update

 if (Input.GetKey(KeyCode.W))
                 {
                     gameObject.transform.position = new Vector3(transform.position.x + 1, transform.position.y, transform.position.z);
                 }
                 if (Input.GetKey(KeyCode.S))
                 {
                     transform.position = new Vector3(transform.position.x - 1, transform.position.y, transform.position.z);
                 }
 
                 if (Input.GetKey(KeyCode.A))
                 {
                     transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + 1);
                 }
                 if (Input.GetKey(KeyCode.D))
                 {
                     transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z - 1);
                 }

Comment
Add comment · Show 5 · 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 UltOCreatE · Jan 03, 2018 at 05:18 PM 0
Share

Thank you for the help, but this is not the movement I'm looking for as there is no jump and I can't seem to make the movement less than 1.

avatar image Ginxx009 UltOCreatE · Jan 04, 2018 at 01:32 AM 0
Share

Could you edit your question and put there the code you use :)

avatar image BeginnerPlzHelp Ginxx009 · Oct 30, 2020 at 06:39 PM 0
Share

sure, this is my code right now but apparently, the public VAR "rb" isn't showing up in the inspector and the movement itself doesn't work either thx again for the help -$$anonymous$$asterrcoder

using UnityEngine;

public class Player$$anonymous$$ovement : $$anonymous$$onoBehaviour {

public Rigidbody rb; //these are the forces that we use; public float forwardForce = 1000f; public float backwardForce = -1000f;
public float rightForce = 1000f; public float leftForce = -1000f;
void FixedUpdate () { if (Input.GetKey("d"))
{ rb.AddForce(rightForce Time.deltaTime, 0, 0); } if (Input.GetKey("a")) {
rb.AddForce(leftForce
Time.deltaTime, 0, 0); } if (Input.GetKey("w"))
{ rb.AddForce(0, 0, forwardForce Time.deltaTime);
} if (Input.GetKey("s"))
{ rb.AddForce(0, 0, backwardForce
Time.deltaTime);
} }

Show more comments
avatar image BeginnerPlzHelp · Oct 27, 2020 at 10:01 PM 0
Share

thank you, you have helped a lot but whenever I copy and paste ur code it give me 24 errors, thank u for trying to help tho, bye

avatar image
1

Answer by CyberGamer1907 · Oct 29, 2020 at 10:35 AM

 private void FixedUpdate()
     {   
         float moveHorizontal = Input.GetAxis("Horizontal");
         Vector3 movement = new Vector3(moveHorizontal, 0, 0);
         transform.Translate(movement);
 
         float moveVertical = Input.GetAxis("Vertical");
         Vector3 movement2 = new Vector3(0, moveVertical, 0);
         transform.Translate(movement2);        
     }
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
avatar image
0

Answer by BeginnerPlzHelp · Oct 27, 2020 at 10:00 PM

I have been struggling to find a good 3d movement script that was actually tested but I couldn't find anything. This was a struggle and I want people to not have to go through what I went through so after 100000 trips to StackOverflow and YouTube I created my own


using UnityEngine;

public class PlayerMovement : MonoBehaviour {

 public Rigidbody rb;

     //these are the forces that we use;
 public float forwardForce = 1000f;
 public float backwardForce = -1000f;    
 public float rightForce = 1000f;
 public float leftForce = -1000f;    

 void FixedUpdate ()
 {
     if (Input.GetKey("d"))    
     {
         rb.AddForce(rightForce * Time.deltaTime, 0, 0);
     }

     if (Input.GetKey("a")) 
     {    
         rb.AddForce(leftForce * Time.deltaTime, 0, 0);
     }

     if (Input.GetKey("w"))    
     {
         rb.AddForce(0, 0, forwardForce * Time.deltaTime);        
             }

     if (Input.GetKey("s"))    
     {
         rb.AddForce(0, 0, backwardForce * Time.deltaTime);        
             }

 }

}

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

81 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

Related Questions

How do I stop momentum in 2D sidescroller? 1 Answer

How to fix my movement? 0 Answers

Player Dash doesn't work properly 0 Answers

Switching characters with camera follow? 0 Answers

How to Apply Animations to Script 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