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 Persona · Sep 14, 2010 at 10:42 PM · triggerwaypointsoncollisionstay

Contact Triggered Waypoint

Does anyone have an idea on how to make it so that once a trigger hits an object, the object is forced along a way-point that's ahead of it and forced to move along it until it reaches the end of the way-point?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by skovacs1 · Sep 15, 2010 at 02:54 PM

You would just setup a waypoint script that is activated on collision like you describe.

MoveScript.js

var wayPoints : Vector3[] = new Array(); //points to move to var moveToWayPoint : boolean = false; //whether to move to points var startPosition : Vector3; //where we are moving from var speed : float = 0.5; //how fast to move (1/speed seconds to move between points) private var weight : float = 0; //how far we've moved from between points private var wayPoint : int = 0; //the point we're moving to

Update() { if(moveToWayPoint && startPosition) { //moving weight += Time.deltaTime * speed; //update how far if(weight >= 1) { //move to the next point weight -= 1; startPosition = wayPoints[wayPoint]; wayPoint++; } if(wayPoint < wayPoints.Length) { //not at the end, so move transform.position = Vector3.Lerp(startPosition, wayPoints[wayPoint], weight); } else { //at the end, so reset weight = 0; wayPoint = 0; moveToWayPoint = false; } } }

TriggerScript.js

OnTriggerEnter(other : Collider) { //collided so make it move to waypoints
    var script : MoveScript = other.gameObject.GetComponent(MoveScript);
    script.StartPosition = other.transform.position;
    script.moveToWayPoint = true;
}

You could put your waypoints wherever you like or generate them somehow (finding one which is ahead of it? what defines being ahead?).

Because of the poor English, I'm not sure if you meant waypoint (singular) (it should read "...the object is forced along a path to a waypoint..." and "...until it reaches the waypoint?") or waypoints (plural) (it should read "...the object is forced along a path of waypoints..." and "...until it reaches the last waypoint?"), so I went with plural and if you only want one, you can simplify it from there.

Comment
Add comment · Show 1 · 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 Persona · Sep 15, 2010 at 08:03 PM 0
Share

Thanks for the help!

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

Trigger on OnCollisionEnter 0 Answers

Waypoints, avoidance, and general advice. 1 Answer

OnCollisionStay melee 1 Answer

OnTrigger ignoring all collisions but the first 1 Answer

Can't click gameobject when over another trigger? 1 Answer


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