• 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 gmkenny · Jun 06, 2019 at 08:16 PM · physicscollidertriggeraddforcecopy

Copy object Movement/Addforce on Trigger to other object,Copy object Movement/Force to object in Trigger

Hey Everyone, I'm building a 2D game and using the physics but I'm having trouble with making a surface that holds a object/player(C) in a areaplatform(B+D), the areaplatform(B+D) is being pushed by a area effector(force) but not in 1 constant direction, it changes on where it is. there are more objects(A) and the edge of the game(black) it can collide with. object/player(c) moves with addforce.

if tried a couple of t$$anonymous$$ng each with not the right out come, making (c) kinematic and giving other movement type inside of (D) makes the movement not smooth. making it a C$$anonymous$$ld of the object doesn't help because a c$$anonymous$$ld doesn't follow forces and making it kinematic is not smooth movement. if tried copping the movement with forces but can't seem to get the right out come. Can someone please help me or tell me if it is possible at all ?

Gravity= 0 A= Copy of B B Parent= polygon Collider2D(B), Rigidbody2D. D C$$anonymous$$ld= C$$anonymous$$ld object with Trigger Collider. C = capsule Collider2D, Rigidbody2D.

alt text

 public class Attempt21 : MonoBehaviour
 {
 
     public Rigidbody2D dragMe;
     public Vector2 resultImp;
     public Vector2 resultDir;
 
     private void OnTriggerStay2D(Collider2D collision)
     {
         if (collision.gameObject.tag == "Atm")
         {
             Rigidbody2D dragMe = collision.gameObject.GetComponent<Rigidbody2D>();
             StartCoroutine(Impulse(setData));
             StartCoroutine(Impulse(setData2));
         }
     }
 
     public void FixedUpdate()
     {
         // ToSlow
         //dragMe.AddForce(-resultDir * resultImp * Time.deltaTime, ForceMode2D.Impulse);
 
         // ToFast
         //dragMe.AddForce(-resultDir * resultImp, ForceMode2D.Impulse);
     }
 
     private IEnumerator Impulse(System.Action<Vector2> Callback)
     {
         Vector2 initialVelocity, newVelocity;
         initialVelocity = transform.GetComponent<Rigidbody2D>().velocity;
         yield return null;
         yield return null;
         yield return null;
         newVelocity = transform.GetComponent<Rigidbody2D>().velocity;
         Vector2 result = initialVelocity - newVelocity;
 
 
         Callback(result);
         Callback(newVelocity);
         yield return null;
     }
 
     public void setData(Vector2 result)
     {
         resultImp = result;
     }
 
     public void setData2(Vector2 newVelocity)
     {
 
         resultDir = newVelocity;
     }
 }


question.png (71.0 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

How to check is object colliding multiple times in one frame 1 Answer

Physics Possibilities?: Angles, Penetration, Exceptions 4 Answers

Raycasts hit triggers disabled - force collision for specific raycast 1 Answer

Is it possible to combine child trigger of a object to only trigger OnTriggerEnter once? 1 Answer

How do I detect when two CharacterControllers collide? 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