Object behavior?

Hello, I have some questions about scripting simple behavior into my game objects.

1: i want to have enemies that, when spawned will continue moving straight until they hit a specified collider, and then go the other direction until they hit a collider, etc. I know how to make an object move in a direction using XYZ and how to use colliders but how do i make the object turn around go the other way(if I set the force to 0, 0, 10 it will always be moving that way)?

2: how can I make it so that a set number of objects are instantiated within a certain radius of another?

3: I want to make a drain type object, when objects come within a certain radius of it they move towords it’s center.

4: completely random drifting around within a certain radius?

5: is there a way to freeze and hide an object from view for a set period of time?

Than you (I know I ask alot of questions)

Not sure what the optimal solution would be, but one thing you could try would be to give the object an initial velocity, and then apply a constant force in the direction of the object’s current velocity. With an appropriate drag setting I think you’d get the effect of a ‘speed cap’, essentially.

Basically, it sounds like what you’re going for is frictionless movement with no drag and perfectly elastic collisions. Even with the correct settings you may or may not get this behavior (due to accumulated numerical error), but maybe with a constant force applied in the direction of the current velocity you can keep the object moving at a more or less constant speed. But, I’m just speculating (I haven’t actually tried it myself).

You can generate random positions inside a specified circle by using Random.insideUnitCircle.

Apply a force through the object’s center of mass and directed towards the position of the ‘drain’ object (the math for this is simple, but ask if you need help with it). Apply the force only when the distance (or squared distance) between the two objects is below the specified radius (you could use a spherical trigger for this as well). If you want more gravity-like behavior, you can make the magnitude of the force proportional to the distance between the two objects.

Depends on the definition of ‘drift’. By ‘within a certain radius’, do you mean the object shouldn’t leave a specified circular or spherical region?

Probably. You can activate and deactivate objects and enable and disable components - is that what you’re looking for?

Depends on the definition of ‘drift’. By ‘within a certain radius’, do you mean the object shouldn’t leave a specified circular or spherical region?

Yeah, I just want it to randomly move around but not leave a specified area.