Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Kongam03 · Jul 07, 2021 at 09:23 AM · movement script2d character

Sliding movement script in 2D (doesn't stop)

Hello! I would need a script that can move the character up, down, right, left (in 2D) so that it slides further and doesn’t stop. Thanks in advance for the comments. :)

Comment
Add comment
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

2 Replies

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

Answer by Anonymous620 · Jul 07, 2021 at 12:27 PM

this is a script that gives the object a steady speed:

         GameObject player;
         public float speed;
         Vector2 direction;
         // Start is called before the first frame update
         void Start()
         {
             player = GameObject.Find("Player");
         }
     
         // Update is called once per frame
         void Update()
         {
             if(direction.y != 0)
             {
                 player.transform.Translate(0, speed * Time.deltaTime * direction.y, 0);
             }
             if(direction.x != 0)
             {
                 player.transform.Translate(speed * Time.deltaTime * direction.x, 0, 0);
             }
             if (Input.GetKey(KeyCode.UpArrow))
             {
                 direction.y = 1;
                 direction.x = 0;
             }
             if (Input.GetKey(KeyCode.DownArrow))
             {
                 direction.y = -1;
                 direction.x = 0;
             }
             if (Input.GetKey(KeyCode.LeftArrow))
             {
                 direction.y = 0;
                 direction.x = -1;
             }
             if (Input.GetKey(KeyCode.RightArrow))
             {
                 direction.y = 0;
                 direction.x = 1;
             }
         }
     

Comment
Add comment · Show 17 · 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 Kongam03 · Jul 07, 2021 at 02:46 PM 0
Share

Thanks for writing the script, it works well. I just want to be able to walk the lines. My question is, can you monitor the pixel color of the line next to the Player? Thanks for the help, I'm still a beginner.alt text

image.png (130.5 kB)
avatar image Anonymous620 Kongam03 · Jul 07, 2021 at 09:50 PM 0
Share

Are the lines line renderers or gameobjects

avatar image rage_co Anonymous620 · Jul 08, 2021 at 05:07 AM 1
Share

It appears that the lines are just a single sprite

Show more comments
avatar image Anonymous620 Kongam03 · Jul 08, 2021 at 06:05 AM 0
Share

Also, in what directions do you want to detect or do you just want to detect in the direction the player is pointing

avatar image Kongam03 Anonymous620 · Jul 08, 2021 at 06:30 AM 0
Share

I'd like to do a similar game to Super Gridder.

https://www.youtube.com/watch?v=WU50VggB79Q

Thank you for your help.

Show more comments
avatar image
0

Answer by Harry_Drew · Jul 07, 2021 at 11:54 AM

Maybe try using rigidbody.Addforce and a low friction on the surface with a physics material?

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

130 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

Related Questions

Player Character No Longer Moving 0 Answers

My player doesn't turn based on the mouse when it's supposed to 0 Answers

Android based ARCore example ObjectManipulation using Joystick Controller 0 Answers

Convert current rigidbody velocity to transform.forward 0 Answers

[2d] Player sometimes doesn't jump up while moving and jumping at the same time 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