How can I make my custom humans tween toward the person who spawned them?
Hey everyone! At the moment I am writing a class for everything that lives in a game I am making. This class is set up as follows currently:
- Object is constructed with a
SelfMesh
(part in workspace)
- Object is given properties (type, occupied, and age)
I have wrote a basic life function called Life:Animate() which at the moment allows the life form to perform five life choices and then they die.
While I am fairly confident the actual life cycle works - the issue seems to be in the possible life choice Life:GoToParent(), in which the life form is supposed to walk toward the person who spawned it. [tl;dr read this paragraph]
(currently the life forms seem to run toward the middle of the baseplate and start to pile up instead of running toward the person who spawned them)
This is the current setup, and my attempt [focus :Animate() and :GoToParent()]:
04 | function Life.new(initType, trueObject, parent) |
06 | setmetatable (thisObject, Life) |
08 | thisObject.Type = initType |
09 | thisObject.SelfMesh = trueObject |
10 | thisObject.Guardian = parent |
11 | thisObject.Occupied = false |
17 | function Life:GoToParent() |
20 | local Parent = game:GetService( "Players" ):FindFirstChild(self.Guardian.Name).Character.HumanoidRootPart |
21 | local SolvedCFrame = CFrame.new(self.SelfMesh.CFrame.p, Parent.Position) |
22 | local Direction = (self.SelfMesh.Position).Unit |
24 | game:GetService( "TweenService" ):Create(self.SelfMesh, TweenInfo.new( 5 ), { Position = Vector 3. new(self.SelfMesh.Position + Direction) } ):Play() |
31 | function Life:Animate(p) |
32 | self.SelfMesh.CFrame = CFrame.new(p) * CFrame.new( 0 , 1 , 0 ) |
36 | local LifeChoice = Random.new():NextInteger( 1 , 1 ) |
38 | if LifeChoice = = 1 then |
41 | repeat wait() until self.Occupied = = false |
44 | self.Age = self.Age + 1 |
52 | self.SelfMesh:Destroy() |
All help is appreciated, thank you!