- Home /
How to add force to rigid body in a direction of another object?
I have a number of cubes falling onto a plane that simulates a conveyor belt. I want to apply a force to those cubes (rigid bodies) so that they move in the direction of the conveyor belt.
using UnityEngine;
using System.Collections;
public class ConveyorBelt : MonoBehaviour
{
void OnCollisionStay (Collision collision)
{
Rigidbody rigidbody = collision.gameObject.rigidbody;
rigidbody.AddForce (Vector3.forward * 10);
}
}
The code above seems to apply a forward force from the cubes point of view. Depending on which direction the cube lands, forward might not be in the direction of the belt.
How to add force to the cubes that matches the direction of the belt?
Answer by Linus · Feb 21, 2014 at 12:34 PM
See http://answers.unity3d.com/questions/535765/conveyer-belt-physics.html
I answered there while you asked this.
Your answer
Follow this Question
Related Questions
Reading the forces applied on a freezed rigidbody(solved) 1 Answer
Unity First person controller force and mass 0 Answers
maximum torque/maximum force 0 Answers
Rigidbody velocity has got different direction than VelocityChange force vector 1 Answer
Adding Rigidbody to an Object on Collision by Raycast? 1 Answer