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 DiamondMC102 · Aug 12, 2017 at 11:04 PM · collider2d game2d-physics

Pulling Objects to Player using force

Let’s say that I have a Player, and my player can walk, run, and jump. Also, my player has a Polygon Collider 2D and if 2D GameObjects( with a Rigidbody2D and Box Collider 2D) are detected in the Polygon Collider 2D the Player will Add Force to movable 2D GameObjects that are in the Polygon Collider 2D to be pulled towards the Player. So I used a Polygon Collider for my Player and a Box Collider for the 2D GameObject that the Player’s Polygon Collider is supposed to pull towards the Player, but I ran into some problems. So the Players Polygon Collider(that is a rectangular shape) that reaches out from the Players right side. Instead of pulling the 2D GameObject towards the Player when it’s in the Players Polygon Collider, the 2D GameObject Box Collider collides with the Players Polygon Collider, now let me explain the position of the Player and 2D GameObject. Now the Player and GameObject are on the middle of a platform, so the Player is on the left side of the Scene screen and the GameObject is on the right, okay now when the Player’s Polygon Collider collides with the 2D GameObject Box Collider the Player is instantly moved to the right by 20 and moved up by 25, and I know it has something to do with this line of code, Rigid.AddForce(new Vector2(20, 25)); .I then decided to try to figure out what happened, so I change the Rigid.AddForce(new Vector2(20, 25)); to Rigid.AddForce(new Vector2(-1, 0)); .Now when the colliders collide it pushes the Player back while leaving the the 2D GameObject in the same position, then I tried Rigid.AddForce(new Vector2(0, 1)); even when the Player Polygon Collider isn’t colliding with the 2D GameObject Box Collider it forces the player into the air, but he eventually comes back down, but the Player falls through the platform.

-By the way, the Player is named “Indingo” in this Unity2D project and so is it’s Tag. Also, the mass of Indingo and the 2D GameObject is 0 with a gravity scale of 1.

Here’s my code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 public class Indingo_Vacuum_Mouth : MonoBehaviour
 {
 private Rigidbody2D Rigid;
 public float vacuumForce;
 // Use this for initialization
 void Start()
 {
 Rigid = GetComponent<Rigidbody2D>();
 }
 // Update is called once per frame
 void Update()
 {
 }
 void OnTriggerEnter2D(Collider2D other)
 {
 if (other.tag != “Player”)
 {
 Rigid.AddForce(new Vector2(20, 25));
 //Do something
 }
 }
 }


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

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

85 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

Related Questions

Sprites not recognized as whole-spinning in different directions 0 Answers

Collider lets object through 0 Answers

Problem with collision with two colliders simultaneously in Unity 2D 1 Answer

*** Trigger Collider2D event only once *** 3 Answers

Unity 2D Collider Safe Sizes 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