x


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.

more ▼

asked Mar 29 '10 at 01:40 AM

e.bonneville gravatar image

e.bonneville
5.7k 100 116 165

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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);
more ▼

answered Mar 29 '10 at 06:41 AM

KvanteTore gravatar image

KvanteTore
1.5k 8 15 33

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

Mar 29 '10 at 01:17 PM e.bonneville

You wouldn't. You would do it just like in KvanteTore's example.

Mar 29 '10 at 04:06 PM Ricardo

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) :)

Mar 29 '10 at 04:22 PM e.bonneville

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.

Mar 29 '10 at 04:29 PM e.bonneville

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

Mar 29 '10 at 04:36 PM e.bonneville
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Mar 29 '10 at 02:20 AM

Sebas gravatar image

Sebas
4k 12 18 45

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.

Mar 29 '10 at 02:27 AM e.bonneville

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

Mar 29 '10 at 11:29 AM Sebas
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Mar 29 '10 at 07:44 AM

Ricardo gravatar image

Ricardo
5.2k 20 32 96

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x252
x243
x86
x48

asked: Mar 29 '10 at 01:40 AM

Seen: 3992 times

Last Updated: Mar 29 '10 at 07:41 AM