2

Im quite new to programming and working with the coding system in Unity. I have searched the web for this but I still haven't found a solution or proper answer.

Could ConstantForce affect a GameObject without a RigidBody?

I am wanting to create a magnetic like effect on my GameObject so that it is pushed backwards like a strong wind on an incline while I am trying to move forward. I tried to use a RigidBody but the gravity of the RigidBody makes the GameObject slide down the incline. Because of this effect I haven't started scripting the movement because I dont want the gameObject to start sliding backwards when forward motion stops. I want this to be done by the ConstantForce.

Thank you in advance for any answers and I hope I was able to explain this well.

1 Answer 1

0

You will need the RigidBody to be able to apply ConstantForce.

Constant Force is a quick utility for adding constant forces to a Rigidbody. This works great for one shot objects like rockets, if you don’t want it to start with a large velocity but instead accelerate.

You can disable the gravity on a RigidBody to solve your problem.

if(collider.attachedRigidbody)
   collider.attachedRigidbody.useGravity = false;
1
  • Does this only work in 3D or can i use it in 2D as well? Nov 6, 2014 at 0:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.