Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 e-bonneville · Mar 29, 2010 at 01:40 AM · pathfindingtargetwalksteering

Moving to points

Hi, I've got a simple problem. I'm struggling to create an RTS game. In it, one must be able to click a unit and move it to a set position. After working all day, I've gotten pretty far, and I'm almost done. What I've done is on mousedown, create an invisible sphere at hit.point (using raycast.hit). The unit targets the sphere, and walks towards it. However, since the sphere is on the ground, the unit will rotate towards it until it is directly over it, at which point, it will be directly over it, and to continue facing it, will rotate until it is horizontal to the ground. This constituted a major problem in my development, as it was completely unrealistic. I sought to counter it by placing a Configurable Joint on my unit. However, the unit simply could not get to the target, because it wanted to rotate, but couldn't because of the C. Joint. It would therefore stop at some distance from the target. How would I fix this?

Thanks in advance - Elliot Bonneville.

P.S. Thanks go to all the people who have already answered my previous (numerous) questions.

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

3 Replies

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

Answer by KvanteTore · Mar 29, 2010 at 06:41 AM

Could you, instead of looking directly at the sphere, do a lookat towards the x and z position of the sphere, and the y position of your object?

Edit: You could possibly use the following C# script to look straight ahead, but towards target:

Vector3 targetPos = target.transform.position;
targetPos.y = transform.position.y;
transform.lookAt(objectPos);
Comment
Add comment · Show 5 · 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 e-bonneville · Mar 29, 2010 at 01:17 PM 0
Share

Well, I'm using the lookat function in the API, and I don't know how to modify that directly.

avatar image Ricardo · Mar 29, 2010 at 04:06 PM 0
Share

You wouldn't. You would do it just like in $$anonymous$$vanteTore's example.

avatar image e-bonneville · Mar 29, 2010 at 04:22 PM 0
Share

I see. In fact, I think I commented before the example. Thanks for pointing it out, I didn't see it. (I don't know how I didn't) :)

avatar image e-bonneville · Mar 29, 2010 at 04:29 PM 0
Share

I tried to convert it JS, but it gave me about 15 errors. I'm not familiar with C#, although I know C++, it's not the same at all.

avatar image e-bonneville · Mar 29, 2010 at 04:36 PM 0
Share

@ $$anonymous$$vanteTore Thanks a ton! I finally got it working. Oh, victory is sweet! lol.

avatar image
1

Answer by Sebas · Mar 29, 2010 at 02:20 AM

Putting the configurable joint just makes things more complicated. Why don't you disable the lookAt as soon as you enter the sphere and solve the rest by just approaching a location which is at a point which you calculate like [sphere center on ground] + [y-value of pivot point of the moving unit]. You just keep moving the last short distance towards that point above ground and no turning downwards will occur.

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 e-bonneville · Mar 29, 2010 at 02:27 AM 0
Share

The problem is, it's turning from quite a while away, although just a little bit, it gets more and more noticable until I hit the trigger, at which point the unit stands straight up. As you can see, that's not very desirable at the moment.

avatar image Sebas · Mar 29, 2010 at 11:29 AM 0
Share

the point to move towards (above your sphere) could be used as a lookat point from the very beginning.

avatar image
1

Answer by Ricardo · Mar 29, 2010 at 07:44 AM

You could look into UnitySteer and the simple MovesToPoint vehicle as an example. Sounds like part of the problem is that the target you're attempting to look at is at ground level, when you should instead be looking at a point that is, so to speak, at "eye-level" for the unit. It's likely all you need is simply adjusting the Y of the target.

Update: Just noticed that's what Kvante said, and upvoted. Leaving the post up as the steering reference is still relevant.

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

No one has followed this question yet.

Related Questions

Having trouble steering gameobject. 0 Answers

object following a path, like train - railroad 4 Answers

How to combine NavMesh Agent with Character Controller 0 Answers

Pathfinding help 1 Answer

A* pathfinder - next target 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