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 theBuilder10000 · Oct 16, 2019 at 02:26 AM · 2d gameplayerphysics2dforcepull

How do I make a tractor beam affect my player?

I have a player that moves around my game normally, and I have an object that has a radius around it that's meant to pull the player into its center to damage it. I'm moving the player using rb.MovePosition. I can get the player to move normally, and I can get the object to pull the player in, but I can't get both things to happen at the same time. Basically I want the player to be pulled in, but only slightly. I want them to be able to escape the pull. How do I make two opposing forces act on the same object.'

 velocity.x = joystick.Horizontal;
 velocity.y = joystick.Vertical;
 rb.MovePosition(transform.position + velocity * speed);
     
 if(attracted == true){
      tractorDirection = tractorBeam.transform.position - transform.position;
 }
 //Trying to add both the tractor direction and the velocity of the player, and to make the force towards the tractor beam less than the input velocity force.
                 

alt text

screen-shot-2019-10-15-at-102555-pm.png (279.9 kB)
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 HappiiGamer · Oct 16, 2019 at 04:24 AM

Hey, try this:

 velocity.x = joystick.Horizontal + pullVelocity.x;
 velocity.y = joystick.Vertical + pullVelocity.y;

Where your pullVelocity is

 pullVelocity = Amplitude of Pull  x Direction of the Pull

Comment
Add comment · Show 2 · 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 theBuilder10000 · Oct 16, 2019 at 05:33 AM 0
Share

Hey thank you for reply. It works perfectly.

avatar image HappiiGamer theBuilder10000 · Oct 16, 2019 at 01:45 PM 0
Share

Happy to hear that! If you want like a gravity pull that gets weaker the farther you are, you can change that Amplitude value based on the distance from your tractor beam. Good luck with your project!

avatar image
0

Answer by GrayLightGames · Oct 16, 2019 at 04:39 AM

Honestly I haven't implemented this kind of gravity, but have you tried something like:

  var tractorDirection = Vector3.zero;
  if(attracted == true){
       var tractorHeading = tractorBeam.transform.position - transform.position;
       tractorDirection = tractorHeading / tractorHeading.magnitude;
  }
 
  tractorGravity = someValueLessThanSpeed;
 
  velocity.x = joystick.Horizontal;
  velocity.y = joystick.Vertical;
  
  rb.MovePosition(transform.position + velocity * speed + tractorDirection * tractorGravity);   

If tractorGravity is less than speed, it should be possible to escape by moving directly away from it. But you can play around with the value until you have what you're looking for.

That vector subtraction gives you a direction with a magnitude(sometimes called a heading), so you have to divide out the magnitude for just the actual direction.

But if someone with more 2D physics experience can correct me, feel free. Hope that helps!

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

165 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Game Object is moving towards the left when fire button is pressed. 2 Answers

how to have air control after a rocket jump? 0 Answers

Butcher-like blood physics and rendering 0 Answers

Basically how to make a fan in Unity2D 1 Answer

Trigger in child - boxcollider2d without trigger on parent issues. 0 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