|
| 23 Oct 2014 01:27 PM |
CreepSpeed = 0.2
function FindPath()
local Creep = script.Parent.Creep local Checkpoint = 1
if script.Parent:findFirstChild("CP" ..Checkpoint) then local CPA = script.Parent["CP" ..Checkpoint] if script.Parent:findFirstChild("CP" ..Checkpoint + 1) then local CPB = script.Parent["CP" ..Checkpoint + 1]
local Distance = (CPA.Position - CPB.Position).magnitude
for i = 0, Distance, CreepSpeed do Creep.CFrame = CFrame.new(CPA.Position - ((CPA.Position - CPB.Position) * (i / Distance))) wait() end
end end end
FindPath()
With a nudge in the right direction and the proper modifications eLunate was able to help me figure out a new method to moving my creeps in tower defense. It works but I would like to get the creeps to face in the direction they're moving.
The only thing I could think of was placing this after the actual CFraming. Problem is that doing so prevents the creep from moving at all. Instead, it just puts him in the middle of the 2 checkpoints, immobile.
Creep.CFrame = Creep.CFrame * CFrame.new(CPA.Position/2 + CPB.Position/2 , CPA.Position) |
|
|
| Report Abuse |
|
|
|
| 23 Oct 2014 02:30 PM |
CFrame.new(CPA.Position,CPB.Position).lookVector
Didn't work either. I just want the Creep to face the direction it's moving. :/
|
|
|
| Report Abuse |
|
|
|
| 23 Oct 2014 03:04 PM |
| It can't be that hard to do. I know I'm missing something important. I just don't see it yet. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 23 Oct 2014 03:22 PM |
Can Roblox turn a normalised vector into a rotation? if so, you've already got it there. (CPA.Position - CPB.Position).unit will be the normalised vector for the direction |
|
|
| Report Abuse |
|
|
|
| 23 Oct 2014 03:31 PM |
I don't know what normalised means and typing unit into the wiki pulls up Rays.
Like this?
* CFrame.Angles(CPA.Position, (CPA.Position - CPB.Position).unit) |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 23 Oct 2014 03:45 PM |
| I don't actually know. I've not worked with CFrame.Angles before, and my knowledge of using normalised vectors for rotations only extends as far as Unity's C# API |
|
|
| Report Abuse |
|
|
|
| 23 Oct 2014 03:57 PM |
Will this help you figure it out? This is the one I use for my attack script. I edited it so that the variables are relative to their respective parts.
Creep.CFrame = CFrame.new(CPA.Position + CFrame.new(CPA.Position,CPB.Position).lookVector * ((CPA.Position-CPB.Position).magnitude/i)* i, CPB.Position)
Believe me, I tried just using that but it glitched out the studio. xD |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 23 Oct 2014 04:44 PM |
| I think I've done it before by multiplying each part by tau or something to get it as a rotation in radians, but eh I don't think that works properly |
|
|
| Report Abuse |
|
|
| |
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 23 Oct 2014 04:58 PM |
I speak a whole different language...
Anyway, can't you just do CFrame.new(Vector3 position, Vector3 unit)? If that even works |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 23 Oct 2014 05:00 PM |
| Creep.CFrame = CFrame.new(CPA.Position - ((CPA.Position - CPB.Position) * (i / Distance)), (CPA.Position-CPB.Position).unit)? |
|
|
| Report Abuse |
|
|
|
| 23 Oct 2014 05:30 PM |
| It does rotate it but not so that it faces CPB dynamically. It rotates it about 135 degrees clockwise from world coordinates specifically. I tried moving CPA and CPb around to see if I could just add a new rotation to fix it but to no avail. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 23 Oct 2014 05:33 PM |
| Does CFrame not rotate it to face the Vector3 relative to its local space? |
|
|
| Report Abuse |
|
|
|
| 23 Oct 2014 05:38 PM |
idk what you mean when you say that
all its supposed to do is go from point A to point B and face point B while its going to it. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 23 Oct 2014 05:40 PM |
I'm really sorry, but I don't know how CFrame rotation works, and I'm on my tablet so I can't test :(
If you don't have an answer in about 10 hours (or just less) from now, shoot me a message and I'll look into it. |
|
|
| Report Abuse |
|
|
|
| 23 Oct 2014 06:13 PM |
| Ill prepare a message to send later, because apparently nobody else knows how to help either. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 23 Oct 2014 06:21 PM |
If you have the direction, you can just do:
local pos = blah.Position blah.Torso.CFrame = blah.Torso.CFrame(pos, pos + direction) where direction is the direction |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 23 Oct 2014 06:24 PM |
| Simple question really. Does it point to world coodinates or local space? |
|
|
| Report Abuse |
|
|
|
| 23 Oct 2014 06:26 PM |
I SORT OF fixed it.
CreepSpeed = 0.2
function FindPath() local Creep = script.Parent.Creep local Checkpoint = 1 if script.Parent:findFirstChild("CP" ..Checkpoint) then local CPA = script.Parent["CP" ..Checkpoint] if script.Parent:findFirstChild("CP" ..Checkpoint + 1) then local CPB = script.Parent["CP" ..Checkpoint + 1] local Distance = (CPA.Position - CPB.Position).magnitude
for i = 0, Distance, CreepSpeed do Creep.CFrame = CFrame.new(CPA.Position + CFrame.new(CPA.Position,CPB.Position).lookVector * ((CPA.Position-CPB.Position).magnitude/Distance) * i, CPB.Position) wait() end end end end
FindPath()
It does it. It goes from Point A to Point B while always facing Point B, but... Well Im not entirely sure how to explain this.
After the Creep reaches Point B it changes height dramatically. Like REALLY dramatically. This is literally the Vector3 of its position AFTER it got to Point B
0, -340282346638528859811704183484516925440, 0
Im not joking at all.
I can reposition it by putting Creep.CFrame = CPB.CFrame directly after the for loop but it doesnt stop the glitch. It just fixes the position after it has already happened. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 23 Oct 2014 06:28 PM |
world (so whatever direction you have, it will point to it regardless of prior rotation)
|
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 23 Oct 2014 06:29 PM |
Okay looks like it points to world coordinates then. (Will remember that Roblox does not like using normalised vectors for directions) |
|
|
| Report Abuse |
|
|
|
| 23 Oct 2014 06:31 PM |
| Perhaps someone can explain why position Y was negative (huge freakin number)? |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 23 Oct 2014 06:34 PM |
| Could be to do with your use of relative space and somehow at some point dividing by 0 (or close to) |
|
|
| Report Abuse |
|
|
|
| 23 Oct 2014 06:44 PM |
| lol id fix it if I knew where. xD |
|
|
| Report Abuse |
|
|