playMaker

Author Topic: RTS/Diablo-esque style movement problems [SOLVED]  (Read 3545 times)

geoquav

  • Playmaker Newbie
  • *
  • Posts: 14
RTS/Diablo-esque style movement problems [SOLVED]
« on: February 27, 2013, 09:05:00 AM »
I am working on some basic movement within an RTS project and am getting stuck on step 1. My goal is to click a part of the map and have my selected unit travel there along the terrain. What I am getting is the unit traveling through the air and ending up in the middle of the terrain.

I am hoping this is a simple mistake that I am overlooking. To further explain this is the process I am using:

1. Use Mouse Pick to get a Vector3 position and store it as a Point.
2. I then use iTween to move to the Vector3 position.

My object that is moving is using a Character Controller. (This can be changed if someone can elaborate on how to activate triggers without a Character Controller, but that's a separate issue.)

Thanks for any help you guys can provide.
« Last Edit: February 27, 2013, 09:58:16 AM by geoquav »

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: RTS/Diablo-esque style movement problems
« Reply #1 on: February 27, 2013, 09:38:46 AM »
Is your mouse pick distance enough to actually hit the terrain? Check if the gameObject yout pick hits is null, if it is, it's not actually colliding and then it'll return the vector (0/0/0) .

Anyways, tween is a fancy unity term for interpolate based on a function (curve). For example, if you tween linearily and have your actor at (0/0/0) and your target at (1/0/2) and want to move between them within 1 second, then your actor is going to be set to the position (0.25/0/0.5) after 0.25 seconds, to (0.5/0/1) after half a second , and to the target after 1 second (well, it does this every frame, so it will seem smooth).
So no matter what, your colliders will not do anything, since they haven't noticed any movement. The actor just happens to change its position.

So while tweening can be useful, this is not one of its' strongsuits.
To make unity colliders (and the character controller really is just a special kind of collider) register the movement and check if that movement is actually possible, you need to use actions like "move" or "simple move". These are especially done for this purpose only.

After making sure that your pick hits and that you use an action that takes collisions into account, you need to think about how far you want to go with your controller. Eg :
p= player
x = goal
I = wall

Imagine they are positioned like this : p   I   x

Then if p moves towards x, it will get stuck : pI   x

This would require the player to carefully click the actor around the wall, so that it does not collide with the wall.

To solve this problem you need Pathfinding, there's no proper way around it. Unity pro has such a system integrated, though it's too young to be used in any real production imo. That leaves you with a couple of plugins most of which cost money and of which all but one are not yet supported by PlayMaker(to my knowledge).
So without advertising my own little project here, I don't think there's much alternatives but Aron Granberg's Pathfinding solution ( http://arongranberg.com/astar/ ) coupled with the Playmaker integration which can be found here : http://hutonggames.com/playmakerforum/index.php?topic=2540.0
[Don't worry, the free version of Astar is more than enough for your purposes]
Best,
Sven

geoquav

  • Playmaker Newbie
  • *
  • Posts: 14
Re: RTS/Diablo-esque style movement problems
« Reply #2 on: February 27, 2013, 09:57:51 AM »
Thanks for that incredibly detailed and quick response. I can confirm that the vector is getting populated with results. You have also helped me figure out what exactly iTween is, I though it was just an advanced move command. I have looked at your project for A* previously but thought it was an extension to the movement and not an actual overall solution.

I will definitely look into it more thoroughly now. Thanks again.