- Home /
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 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.
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;
}
}
Your answer
Follow this Question
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