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 iRaaptor · Aug 05, 2014 at 04:14 AM · collisionmovementvelocity

2D Movement [HELP!]

How do I make it so that the player moves towards the mouse with velocity?

         if(Input.GetKey (KeyCode.W)){
             facing = 3;
             transform.position = Vector3.MoveTowards(transform.position, pos, movementspeedCurrent * Time.deltaTime);
         }

This code doesn't use velocity, but does make the character move towards the mouse. Only problem is that it moves INSIDE of the objects it collides with, it teleports in a little bit and teleports out, and repeats. Colliding doesn't work.

 rigidbody2D.velocity = new Vector2(movementspeedCurrent,0);


this works, no collisions issues, it hits the object it collides with, and instantly stops. This is what I want. Only problem is that it doesn't move to the mouse, and I'd expect that, because I'm only making it move left/right with this code.

This is why I like velocity, the collisions are precise. Although, if there is a way to fix the player moving in and out of the object it collides with, and making it just stop solidly when colliding with an object with a Box Collider 2D, please help.

I don't HAVE to use Velocity, that's all I know that works at this time. If you've got a better way to move the character, please, tell me.

 rigidbody2D.velocity = Vector2.MoveTowards(transform.position, targetPos, movementspeedCurrent*Time.deltaTime);

tried this and expected it not to work. It does not work.

This game is 2D with an Orthographic camera.

Edit: Overhead game

Comment
Add comment · Show 3
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 iRaaptor · Aug 05, 2014 at 09:07 AM 0
Share

bump.........

avatar image iRaaptor · Aug 05, 2014 at 09:16 AM 0
Share

bump........

avatar image siddharth3322 · Aug 05, 2014 at 09:33 AM 0
Share

I think you have to view this video Top Down 2D Game Basics for player movement.

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

rigidbody It's going up and bounces when is moving 1 Answer

Disabling gravity when colliding with the terrain? 0 Answers

Velocity remains constant even when colliding 0 Answers

How do I move this rigidbody? 1 Answer

Player glitching through wall when sprinting 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