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 ROM · Jun 19, 2010 at 03:26 PM · movementiphonesimplewaypointsx-axis

Movement between waypoints?

So I'm moving a cube between waypoints, now my problem is that i only want it to align itself with the waypoints along the xaxis, i don't want it to float through the air to reach them and I want gravity to remain active whilst it moves between them.

Heres my code so far:

var waypoint: Transform[]; var speed : float = 20; private var currentWaypoint:int;

var loop : boolean = true;

function Awake(){ waypoint[0] = transform ; } function Update () { if(currentWaypoint < waypoint.length){ var target : Vector3 = waypoint[currentWaypoint].position; var moveDirection : Vector3 = target - transform.position;

     var velocity = rigidbody.velocity;

     if(moveDirection.magnitude &lt; 1){
         currentWaypoint++;
     }
     else{
         velocity = moveDirection.normalized * speed;
     }
 }
 else{
     if(loop){
         currentWaypoint = 0;
     }
     else{
         velocity = Vector3.zero;
     }
 }

 rigidbody.velocity = velocity;

}

How would I go about doing this?

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
0
Best Answer

Answer by Tetrad · Jun 19, 2010 at 05:17 PM

It sounds like you want to have your object moving along the ground (is the ground flat?) and just moving to where the waypoint would be projected onto the ground (use Physics.Raycast to determine where that is by raycasting up or down).

A simple thing to do that might work is to change your rigidbody math to instead use AddForce instead of using .velocity directly. (This is to let gravity and collision stuff do its trick.) Maybe make your vertical component of the vector you calculated to go to the next waypoint zero so it doesn't apply force upwards. Maybe change the physics properties of your collider so it slides across the ground easier. There are lots of little things you can play around with if you have a small set of requirements.

(Also, rigidbody updates should go in FixedUpdate, not Update.)

These suggestions are pretty naive, honestly, and you really should look into more advanced pathfinding solutions: http://answers.unity3d.com/questions/tagged/pathfinding

The aligning to the x axis is easy, just do transform.rotation = Quaternion.Euler( target.transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, transform.rotation.eulerAngle.z ); (Although you'll probably want to use some kind of lerping from the Quaternion class to make the rotation smooth.)

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 Herman-Tulleken · Nov 08, 2010 at 06:24 AM 0
Share

Why not transform.rotation = target.transform.rotation ?

avatar image Tetrad · Nov 08, 2010 at 05:03 PM 0
Share

@Herman, since if you do that you won't guarantee that you're facing up.

avatar image Herman-Tulleken · Nov 09, 2010 at 05:28 AM 0
Share

@Tetrad Oh, now I see (skim$$anonymous$$g over the line, I thought all the angles were on the target)

avatar image ashi200 · Jul 01, 2013 at 11:27 AM 0
Share

can object be made to move between two waypoints in air so that object seems to fly while moving from one waypoint to other ?

avatar image
0

Answer by vickygroups · Jun 04, 2014 at 09:30 PM

great post. fixed my waypoints :)

Comment
Add comment · 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

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

2 People are following this question.

avatar image avatar image

Related Questions

SpeedUp (Beginner project RollBall) 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to Modify Multiplayer Script for iPhone 0 Answers

Accelerometer being able to not affect one item 1 Answer

Making a bubble level (not a game but work tool) 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