Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

Moving rigidbody with addforce to certain position

$
0
0
Hello :) I am trying to make a rigidbody(pusher) move back and forth using addforce. The reason for the add force is so that objects on top of the rigidbody move, instead of freeze like using .translate, etc. I want the pusher to go from start (0,0.005,-12) [empty game object at this location] to end (0,0.005,-8) [empty game object at this location] but once it hits the end, to go back to the start, over and over. The other thing to take into account is, that the object count on top of the pusher can vary. I want the pusher to move at a certain speed instead of being dependent on the amount of weight on the pusher. Here is what I have so far. Thank you to all who assist on this, as it's been 3 hours of no luck searching for a real answer. :) I had to pull out a good bit of the old code to make it a better base. using UnityEngine; using System.Collections; public class SlidingPusher : MonoBehaviour { public Rigidbody Pusher; public Transform start; public Transform end; void Start() { } void FixedUpdate() { if (Pusher.rigidbody == (end.position)) { Pusher.rigidbody.AddForce (start.position, 10); } } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles