# Push an object along a path?

 0 I've read iTween is good for this but the only one i can find is to move it. I want my character to move say a boulder out of the way by pushing it, but only to a certain point? Like say the character pushes the boulder to the end point which then triggers an event of some kind because it's on top of a switch maybe? Just to give an example? I'm not asking for like the whole move and push to an event just how to move say a boulder to a certain point that it stops moving? more ▼ asked Apr 07 '11 at 03:57 PM Matt 21 9 ● 5 ● 6 ● 9 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 You can use a distance check. You need a few varaibles: Vector3 targetPoint - The target in world space. float actionDistance - How far the boulder needs to be from targetPoint before triggering the action. If you want the boulder to have to be in a specific spot set this equal to the boulder's radius float radius - The radius of the boulder. Here is some code ``````public void Move(Vector3 pushForce) { // First, update our position based on the push applyed by the player transform.position += playerPushForce * Time.deltaTime; // Find a vector going from the center of this boulder to the target point Vector3 difference = targetPoint - transform.position; // If the distance is less than the actionDistance - radius, then we have a hit // (the dot product of a vector with its self is the squared magnitude of said vector) if (Vector3.Dot(difference, difference) < (actionDistance * actionDistance) - (radius * radius)) { // Hit it! } } `````` more ▼ answered Apr 07 '11 at 08:31 PM Gabriel 4 57 ● 10 ● 11 ● 18 I'm a complete begginner to all of this, i get the pplayer push force, but the vector difference i'm baffled by. No idea how to work this. Sorry. Apr 07 '11 at 08:52 PM Matt 21 When you subtract v1 from v2 (v2 - v1) you get a new vector. This vector points from v2 to v1. http://www.sparknotes.com/testprep/books/sat2/physics/chapter4section3.rhtmlThe difference vector is a vector pointing from the boulders position to the target position. (If you need to visualize it, try Debug.DrawLine())We can use the length of this vector to determine how far the boulder is from it's target. Apr 11 '11 at 06:31 PM Gabriel 4 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x3722
x1091
x426
x237
x70

asked: Apr 07 '11 at 03:57 PM

Seen: 1713 times

Last Updated: Apr 07 '11 at 08:04 PM