Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Matt 21 · Apr 07, 2011 at 03:57 PM · objectitweenpathpush

Push an object along a path?

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Justin Warner · Apr 07, 2011 at 04:01 PM

Um, a way to go about this...

Give the "boulder" a rigid body... And then add a collider that's attatched to it, so that when you move it, it only moves because of the physics, and stops when it hits the collider... Could be easy...

Alt: You can animate this... if player goes to spot A, and pushes F, then boulder rotates and moves ->>> if that makes sense.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Matt 21 · Apr 07, 2011 at 04:19 PM 0
Share

Give the "boulder" a rigid body... And then add a collider that's attatched to it

i can't get my head around that bit, i'm probably being a bit dozy but what do you mean?

avatar image Justin Warner · Apr 07, 2011 at 09:59 PM 0
Share

Well, the rigid body makes it effected by physics... So, if you do that, the ball will roll... So, I suggested add a collider that's a child, and so that while it's rolling, it knows when to stop bc that collider'll stop it.

avatar image Matt 21 · Apr 07, 2011 at 11:14 PM 0
Share

I've got cubes set up so they move when pushed, but i still dont understand how the collider wil know when to stop it at a certain point?

avatar image Justin Warner · Apr 07, 2011 at 11:36 PM 0
Share

Alright... So, with this example, you can see, when the "player" pushes the "rock" (Sphere) it moves... you can easily do this in your game... I added a collider, but I don't think it helps much... $$anonymous$$ight actually hurt it haha. http://www.2shared.com/file/6CTk1ta9/TESTING_OTHERS.html

avatar image
0

Answer by Gabriel 4 · Apr 07, 2011 at 08:31 PM

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!
        }
    }

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Matt 21 · Apr 07, 2011 at 08:52 PM 0
Share

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.

avatar image Gabriel 4 · Apr 11, 2011 at 06:31 PM 0
Share

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.rhtml

The 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 deter$$anonymous$$e how far the boulder is from it's target.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

A node in a childnode? 1 Answer

How to change object colors? 1 Answer

Itween keep speed constant 1 Answer

What is the best way to store a large number of object positions? 1 Answer

iTween Camera Jitter while moving on path 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges