Problem on Area Effector 2D

Hi Guys, i have a question for 2D game. I am creating a infinity runner game with 0 gravity scale on my characters’ rigidbody2d ( so it is flying). the gravity for the physic is set at default -9.81. I attempted to create a moving “area effector 2d” using a box collider. Everything was fine before my character moving into the area. When my character went into the box collider zone, the character is affected by the force (this is desired result). However, once the character left the zone, the character still being affected by the force.

Update: i have tried to modified the box collider to make it smaller (x and y to 1). And they still provide the same outcome.

Any idea on this?

Just in case any beginner fall into this problem, i’ve decided to keep this here with a solution provided by @Anthony#8354 @ discord.


[SOLUTION:] "
Anthony:
Your drag is set to 0 right?
In the absense of any external forces (such as drag or gravity), an object in motion should stay in motion until another force is acted on it.
It should retain the same velocity even after it leaves the effector zone, it’s just that there’s no additional force to increase or change that velocity."

Yes. I’ve got a very wrong concept that the getAxis input i keyed in will create a force (since the character is moving forward. i thought by moving right will causes the forces neutralize themselve but it will not in fact! Many thanks for those who extended their help


As for the movement, all i have are these

public class playerScript : MonoBehaviour {

public Vector2 speed = new Vector2 (50, 50);

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

	float inputX = Input.GetAxis ("Horizontal");
	float inputY = Input.GetAxis ("Vertical");

	Vector3 movement = new Vector3 (speed.x * inputX, speed.y * inputY, 0);

	movement *= Time.deltaTime;

	transform.Translate (movement);

Screenshot 1 on the box collider:

Screenshot 2 on the player

Nothing obviously sticks out mate. Can I suggest you create a barebones scene with only the elements that relate to this problem, and see if you reproduce it. If you’re still hitting a brick wall, run up a dummy project with the problem, and post that on a git repo so we can download it and debug? PSA: How to ask for help with Unity

1 Like

Thanks ninjachimp
working on bitbucket (accidentally trashed my whole project earlier)

Anyhow, the problem was solved by @Anthony#8354 @ Discord.

Many thanks to those who extended their helps!

1 Like

Glad to hear it. It might help someone else if you could post the solution in here - pay it forward :slight_smile:

Updated the post with a solution. Cheers