- Home /
2D Faux Gravity using a Point Effector?
I have a planet, and a player. The planet has a Point Effector and a "surface collider". The player too has its own collider and of course a rigidbody. When the player is suspended above the planet, and the scene is played, the player collides with the planet in the way you would expect. However when I attach my "Player Movement" script to the player, the player no longer collides with the surface collider and it does glitchy spasms inside the planet. Example of what should happen:
Example of what actually happens:
The movement script:
void Update ()
{
MoveDir = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, 0).normalized;
}
void FixedUpdate ()
{
myRigidBody.MovePosition (transform.TransformDirection (MoveDir) * movespeed * Time.deltaTime);
}
Answer by Alec-Slayden · Jun 13, 2015 at 01:29 AM
It looks like you might be using Rigidbody.MovePosition() as though it were similar to Translate(), but this is incorrect.
Rigidbody.MovePosition moves the object directly to that position in space, not along that axis like Translate does. Rigidbody.MovePosition(Vector) is like saying Transform.Position = Vector, except that the rigidbody will calculate collisions for everything between its current position and the destination.
So what it looks like you're doing is actually telling your rigidbody to go very close to Vector3.zero, every frame of fixed update, and also calculate collisions in between. This is probably going to have some glitchy behaviour.
What you may want to do is AddForce for false gravity