need help with attracting player to an object 😕

i need to attract a player object to certain object was thinking of using constant force but was wondering if there was a better way if so i am open to suggestions at the moment not sure how i can do this there will be multi able objects that i want to be attracted to so i was thinking of creating a custom script using the onEnter function to test if a trigger around the player is triggered and then use relative force…

any help you can give would be greatly appreciated.

Virtual :wink:

How is your player controlled? Rigid body? Kinematic rigid body? Character controller?

yeah sorry using a ridgid body

The simplest solution would probably be to apply a force directed towards the object of interest in FixedUpdate(). The code might look something like this:

Vector3 direction =
    attractingObject.transform.position - player.transform.position;
// This assumes that the object positions won't be coincident or
// nearly coincident:
direction.Normalize();
player.rigidbody.AddForce(direction * forceMagnitude);

If you want the effect to be more like that of gravity, you can scale the magnitude of the force accordingly.

Yeah thanks jessie will use that approch seams a lot better then what i was thinking using realtive force :smile: thanks mate