Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

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

$
0
0
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 thing 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 Child of the object doesn't help because a child 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 Child= Child object with Trigger Collider. C = capsule Collider2D, Rigidbody2D.** ![alt text][1] 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(); 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 Callback) { Vector2 initialVelocity, newVelocity; initialVelocity = transform.GetComponent().velocity; yield return null; yield return null; yield return null; newVelocity = transform.GetComponent().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; } } [1]: /storage/temp/139622-question.png

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>