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
1
Question by enrpdla · May 08, 2014 at 11:42 AM · vector32d-platformer

Unity rigidbody2D with Vector3

Hi, I'm trying to make repel function(2D platform). I found this code below in the sample project of unity2D

Vector3 hurtVector = transform.position - enemy.position + Vector3.up 5f; rigidbody2D.AddForce(hurtVector hurtForce);

So I just removed "+ Vector3.up * 5f;" part and thought it would work. But it didn't work as I expected. So I tested several Vector3 to see how things work.

Vector3(0, 1, 0) worked fined. My object moved up as expected. However, Vector3(1, 0, 0) and Vector3(0, 0, 1) didn't work as I expected. My object didn't move forward nor right, only slightly dragged along with ground.

Why would only y-axis work fine and x,z-axis not?

Where have I gone wrong? Is there any solution?

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 Sisso · May 08, 2014 at 12:23 PM 0
Share

Which value is hurtVector when you use Vector3(1,0,0) and Vector3(0,1,0)?

avatar image enrpdla · May 08, 2014 at 12:40 PM 0
Share

hurtVector = new Vector3(1,0,0); or hurtVector = new Vector3(0,1,0); is what I did when testing.

avatar image Sisso · May 08, 2014 at 05:13 PM 0
Share

Your code generate much more power that 1 (the distance + 5), try with Vector3(100, 0, 0).

Is this runnig inside a FixedUpdate?

avatar image enrpdla · May 08, 2014 at 06:49 PM 0
Share

It's in OnCollisionEnter2D. If I give really big x-value, like 10000, it just get dragged along ground short distance really fast(teleports). I think I'm getting something. When I make the object 'steps on' the repelling object, it works as expected. Can it be some friction with ground?

avatar image robinrei · May 08, 2014 at 08:35 PM 0
Share

I would bet that it's because you're dragging along the ground, and since it's a force being added to the rigidbody, that force is being lossed in friction. Try doing Vector3(1, 1, 0)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Sisso · May 08, 2014 at 12:22 PM

I have half of the answer. 2d "don't have" the Z axis, so don't expect movement back and forward.

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

22 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

Related Questions

Question about Rays and why getPoint function 1 Answer

Linking array of sets of vector3's together 1 Answer

InverseTransformDirection and TransformDirection 1 Answer

why is my cube moving sideways in inconsistent distances? 2 Answers

nullifying targetObject after a Smooth LookAt Transition 2 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