I was just wondering if there was a way of prevent the player from leaving the effectors area of effect once the player has entered it. At the moment the player can push past the forces from the point effector. I want the player to get sucked in and unable to leave, even if the player is using input.
I did try using on trigger enter to change the player’s velocity within the radius:
using UnityEngine;
using System.Collections;
public class NetsManager : MonoBehaviour {
public Animator Netanimator; //Animator for the nets that will capture the player.
public Vector2 movePlayer;
public Collider2D NetCollider;
void Start()
{
NetCollider.enabled = true;
}
public void OnTriggerEnter2D(Collider2D other)
{
//Debug.Log ("Turtle has entered the coillider");
// if the player has collided with the net.
if (other.tag == "Player")
{
NetCollider.enabled = true;
other.GetComponent<Rigidbody2D> ().MovePosition(Vector2.down - movePlayer * Time.unscaledDeltaTime); //Stop the velocity of the object taged player.
//Debug.Log("Turtle is caught in net");
//other.GetComponent<Rigidbody2D> ().drag = 10; //increase the drag appiled to the rigidbody of the player.
Invoke("StopNetAnimator", 2f); //start the void stop net animator in 2 sceonds.
}
}
public void StopNetAnimator ()
{
NetCollider.enabled = true;
Netanimator.enabled = false; //the net's animation is now disabled. Since player is caught, the net's animator has no reason to countine to the end of the animation clip.
//Debug.Log("Net animator is disabled");
}
}
With what I posted above was an successful attempt at keeping the player in the middle of the effector, I was simply just saying I tried to do what you asked.
Using this line (line 23 of the above script):
other.GetComponent<Rigidbody2D> ().MovePosition(Vector2.down - movePlayer * Time.unscaledDeltaTime); //Stop the velocity of the object taged player.
I don’t see how the script you posted is doing what I suggested which is to stop moving the player when it is within the effector area. You’re using MovePosition on something there, presumably the player.
Stop taking input and stop applying movement to the player was my suggestion.
In that case, the effector should simply exert more force than the player is able to. Think of a black hole: You can try to go as fast as you can, yet the hole is sucking you in, because its force is stronger.