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
0
Question by DaRaccoon · Oct 27, 2018 at 05:07 PM · unity 2drigidbody2dvector2

Push an Object with a vector created from two points.

Hi, i wanted to push my Player in the direction of a vector created with the coordinate of mouseDown and mouseUp. I know, by reading in other questions, that to get a direction vector with those two coordinate i just have to create a Vector2 direction = mouseDownPosition - mouseUpPosition by using the designated void functions, but i seem to get the forces of the push wrong. if i have a fixed value pushForce, what RigidBody2D function should i use to make it seem like a "catapult-y" push? if i just use GetComponent.AddForce(direction * pushForce) the character moves but with almost no "x" force and too much "y" force. Here's what happens on my OnMouseUp() function:

 public float pushForce = 10.0f;
 
 private void OnMouseUp()
         {
             mouseUp = Input.mousePosition;
             Vector2 pushCharacter = mouseDown - mouseUp;              
             GetComponent<Rigidbody2D>().AddForce(pushCharacter * pushForce);       
         } 

i know pushForce could seem little but it's just to make you see what kind of value i use, i tried with every kind of number but the problem it's always the same. for mouseDown i used the same method i used for mouseUp.

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 hexagonius · Oct 27, 2018 at 05:22 PM 0
Share

the way you create the vector is towards mouse down. in addition, mouse positions are in screenspace, which can just usually does not match what the camera sees. transform the points into world space and calculate their force there. and then there's a version of AddForce with a second parameter where you can define how and if with mass considered you want to fire it off.

avatar image DaRaccoon hexagonius · Oct 28, 2018 at 12:05 PM 0
Share

How do i transform those points into world space?

avatar image DaRaccoon hexagonius · Oct 28, 2018 at 12:08 PM 0
Share

but then again, i read that it is for 3D games but in 2D ones the points are already in screen space

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

98 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

Related Questions

Rigidbody2D.Velocity = Vector2 not changing X Position 1 Answer

toss up game object into air with freefall physics 1 Answer

How do I do rb.AddForce but in 2D? 1 Answer

How do I make it so the player cant spam the dash 1 Answer

How would you check if an object is closer to the bottom side or top side of another object 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