generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: A.I Animation (HELP!)

Previous Thread :: Next Thread 
marcusmw331 is not online. marcusmw331
Joined: 07 Jun 2010
Total Posts: 4562
02 May 2013 11:02 PM
This script works perfectly in solo mode forever. When I go into online mode, the A.I freezes after 10 or so seconds. No other scripts are affecting the animation. But there is a weld connecting the head to the torso, could that be a problem? Please help.

function waitForChild(parent, childName)
local child = parent:findFirstChild(childName)
if child then return child end
while true do
child = parent.ChildAdded:wait()
if child.Name==childName then return child end
end
end

-- ANIMATION

-- declarations

local Figure = script.Parent
local Torso = waitForChild(Figure, "Torso")
local RightShoulder = waitForChild(Torso, "Right Shoulder")
local LeftShoulder = waitForChild(Torso, "Left Shoulder")
local RightHip = waitForChild(Torso, "Right Hip")
local LeftHip = waitForChild(Torso, "Left Hip")
local Humanoid = waitForChild(Figure, "Enemy")
local pose = "Standing"

local jumpMaxLimbVelocity = 0.75

-- functions

function onRunning(speed)
if speed>0 then
pose = "Running"
else
pose = "Standing"
end
end

function onClimbing()
pose = "Climbing"
end

function onGettingUp()
pose = "GettingUp"
end

function onFallingDown()
pose = "FallingDown"
end

function move(time)
local amplitude
local frequency

local climbFudge = 0

if (pose == "Running") then
if (RightShoulder.CurrentAngle > 1.5 or RightShoulder.CurrentAngle < -1.5) then
RightShoulder.MaxVelocity = jumpMaxLimbVelocity
else
RightShoulder.MaxVelocity = 0.15
end
if (LeftShoulder.CurrentAngle > 1.5 or LeftShoulder.CurrentAngle < -1.5) then
LeftShoulder.MaxVelocity = jumpMaxLimbVelocity
else
LeftShoulder.MaxVelocity = 0.15
end
amplitude = 1
frequency = 9
elseif (pose == "Climbing") then
RightShoulder.MaxVelocity = 0.5
LeftShoulder.MaxVelocity = 0.5
amplitude = 1
frequency = 9
climbFudge = 3.14
else
amplitude = 0.1
frequency = 1
end

desiredAngle = amplitude * math.sin(time*frequency)

RightShoulder:SetDesiredAngle(desiredAngle + climbFudge)
LeftShoulder:SetDesiredAngle(desiredAngle - climbFudge)
RightHip:SetDesiredAngle(-desiredAngle)
LeftHip:SetDesiredAngle(-desiredAngle)
end



-- connect events

Humanoid.Running:connect(onRunning)
Humanoid.GettingUp:connect(onGettingUp)
-- main program

local runService = game:service("RunService");

while Figure.Parent~=nil do
local _, time = wait(0.1)
move(time)
end
Report Abuse
Sp1nt3rC311 is not online. Sp1nt3rC311
Joined: 10 Aug 2009
Total Posts: 442
03 May 2013 07:41 AM
Okay, if you could do something for me it'd help me a ton in helping you fix your problem. Instead of Test>Solo, go to Test>Server, then once that new window opens up, go to Test>Player. Then from the Server window you can view the output. It mimiks an online server, but unfortunately it doesn't always work 100% of the time. Anyway, that's your best shot at determining the problem. If you get any error messages please copy and paste so I can see them, then hopefully we can figure this out.
Report Abuse
cart6157 is not online. cart6157
Joined: 28 Feb 2009
Total Posts: 2194
03 May 2013 08:04 AM
@above

This script isn't wrong, it's just a roblox problem. I also made a place with lots of AIs walking around, and it also only works in play solo mode but not correctly in play mode. Unfortunately you can't fix this.
Report Abuse
Sp1nt3rC311 is not online. Sp1nt3rC311
Joined: 10 Aug 2009
Total Posts: 442
03 May 2013 08:21 AM
Is this just a script you put into any Humanoid? If so I can copy and paste it, work on it a bit and see if I get anything.
Report Abuse
StealthKing95 is online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
03 May 2013 09:53 AM
Is that a localscript or a serverside script
Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
03 May 2013 12:03 PM
"This script isn't wrong, it's just a roblox problem".

I kind'a doubt this: I have AI walking around, and I count on their Animation not dying.

This looks like the slimest Animation script, I have seen around, so use a different, older one; just to eleiminate the possiblility that this one just doesn't work...

If u still have the same problem, then at least u know that it is not this script.

I don't see how putting a neck in could cause a problem (u do not even mention the neck in the script), but I know very little about Welds, sorry. I put a Spine in mine, and have not noticed a prob.



Bri
.
Report Abuse
marcusmw331 is not online. marcusmw331
Joined: 07 Jun 2010
Total Posts: 4562
03 May 2013 07:52 PM
@Sp1nt3rC311

Even as someone who uses Roblox Studio for years, I didn't even know this.

The animations glitch up just like how they do in the real game. There's no error messages though.
Report Abuse
marcusmw331 is not online. marcusmw331
Joined: 07 Jun 2010
Total Posts: 4562
03 May 2013 07:53 PM
@cart6157

I'm also doubtful on that. Avoid the Odds has way more A.Is than me, and they don't glitch.
Report Abuse
marcusmw331 is not online. marcusmw331
Joined: 07 Jun 2010
Total Posts: 4562
03 May 2013 07:54 PM
@Sp1nt3rC311

You place the script in a model.
Report Abuse
marcusmw331 is not online. marcusmw331
Joined: 07 Jun 2010
Total Posts: 4562
03 May 2013 08:03 PM
@StealthKing95

Just a normal script, not local.
Report Abuse
marcusmw331 is not online. marcusmw331
Joined: 07 Jun 2010
Total Posts: 4562
03 May 2013 08:06 PM
@BJCarpenter

The script did mention a neck so I took it out.
Report Abuse
Usering is not online. Usering
Joined: 18 Aug 2012
Total Posts: 10281
03 May 2013 08:08 PM
This one works online, just put it in a normal script.

wait()

function waitForChild(parent, childName)
local child = parent:findFirstChild(childName)
if child then return child end
while true do
child = parent.ChildAdded:wait()
if child.Name==childName then return child end
end
end

-- ANIMATION

-- declarations

local Figure = script.Parent
local Torso = waitForChild(Figure, "Torso")
local RightShoulder = waitForChild(Torso, "Right Shoulder")
local LeftShoulder = waitForChild(Torso, "Left Shoulder")
local RightHip = waitForChild(Torso, "Right Hip")
local LeftHip = waitForChild(Torso, "Left Hip")
local Neck = waitForChild(Torso, "Neck")
local Humanoid = waitForChild(Figure, "Humanoid")
local pose = "Standing"

local toolAnim = "None"
local toolAnimTime = 0

-- functions

function onRunning(speed)
if speed>0 then
pose = "Running"
else
pose = "Standing"
end
end

function onDied()
pose = "Dead"
end

function onJumping()
pose = "Jumping"
end

function onClimbing()
pose = "Climbing"
end

function onGettingUp()
pose = "GettingUp"
end

function onFreeFall()
pose = "FreeFall"
end

function onFallingDown()
pose = "FallingDown"
end

function onSeated()
pose = "Seated"
end

function onPlatformStanding()
pose = "PlatformStanding"
end

function moveJump()
RightShoulder.MaxVelocity = 0.5
LeftShoulder.MaxVelocity = 0.5
RightShoulder.DesiredAngle = 3.14
LeftShoulder.DesiredAngle = -3.14
RightHip.DesiredAngle = 0
LeftHip.DesiredAngle = 0
end


-- same as jump for now

function moveFreeFall()
RightShoulder.MaxVelocity = 0.5
LeftShoulder.MaxVelocity = 0.5
RightShoulder.DesiredAngle = 3.14
LeftShoulder.DesiredAngle = -3.14
RightHip.DesiredAngle = 0
LeftHip.DesiredAngle = 0
end

function moveSit()
RightShoulder.MaxVelocity = 0.15
LeftShoulder.MaxVelocity = 0.15
RightShoulder.DesiredAngle = 3.14/2
LeftShoulder.DesiredAngle = -3.14/2
RightHip.DesiredAngle = 3.14/2
LeftHip.DesiredAngle = -3.14/2
end

function getTool()
for _, kid in ipairs(Figure:GetChildren()) do
if kid.className == "Tool" then return kid end
end
return nil
end

function getToolAnim(tool)
for _, c in ipairs(tool:GetChildren()) do
if c.Name == "toolanim" and c.className == "StringValue" then
return c
end
end
return nil
end

function animateTool()

if (toolAnim == "None") then
RightShoulderdDesiredAngle = 1.57
return
end

if (toolAnim == "Slash") then
RightShoulder.MaxVelocity = 0.5
RightShoulder.DesiredAngle = 0
return
end

if (toolAnim == "Lunge") then
RightShoulder.MaxVelocity = 0.5
LeftShoulder.MaxVelocity = 0.5
RightHip.MaxVelocity = 0.5
LeftHip.MaxVelocity = 0.5
RightShoulder.DesiredAngle = 1.57
LeftShoulder.DesiredAngle = 0
RightHip.DesiredAngle = 1.57
LeftHip.DesiredAngle = 1.0
return
end
end

function move(time)
local amplitude
local frequency

if (pose == "Jumping") then
moveJump()
return
end

if (pose == "FreeFall") then
moveFreeFall()
return
end

if (pose == "Seated") then
moveSit()
return
end

local climbFudge = 0

if (pose == "Running") then
RightShoulder.MaxVelocity = 0.15
LeftShoulder.MaxVelocity = 0.15
amplitude = 1
frequency = 9
elseif (pose == "Climbing") then
RightShoulder.MaxVelocity = 0.5
LeftShoulder.MaxVelocity = 0.5
amplitude = 1
frequency = 9
climbFudge = 3.14
else
amplitude = 0.1
frequency = 1
end

desiredAngle = amplitude * math.sin(time*frequency)

RightShoulder.DesiredAngle = desiredAngle + climbFudge
LeftShoulder.DesiredAngle = desiredAngle - climbFudge
RightHip.DesiredAngle = -desiredAngle
LeftHip.DesiredAngle = -desiredAngle

local tool = getTool()

if tool then

animStringValueObject = getToolAnim(tool)

if animStringValueObject then
toolAnim = animStringValueObject.Value
-- message recieved, delete StringValue
animStringValueObject.Parent = nil
toolAnimTime = time + .3
end

if time > toolAnimTime then
toolAnimTime = 0
toolAnim = "None"
end

animateTool()


else
toolAnim = "None"
toolAnimTime = 0
end
end


-- connect events

Humanoid.Died:connect(onDied)
Humanoid.Running:connect(onRunning)
Humanoid.Jumping:connect(onJumping)
Humanoid.Climbing:connect(onClimbing)
Humanoid.GettingUp:connect(onGettingUp)
Humanoid.FreeFalling:connect(onFreeFall)
Humanoid.FallingDown:connect(onFallingDown)
Humanoid.Seated:connect(onSeated)
Humanoid.PlatformStanding:connect(onPlatformStanding)

-- main program

local runService = game:service("RunService");

while Figure.Parent~=nil do
local _, time = wait(0.1)
move(time)
end
Report Abuse
marcusmw331 is not online. marcusmw331
Joined: 07 Jun 2010
Total Posts: 4562
03 May 2013 08:16 PM
I know. Problem is I don't want them to hold weapons or swim. My goal is to remove all unneeded scripting.
Report Abuse
marcusmw331 is not online. marcusmw331
Joined: 07 Jun 2010
Total Posts: 4562
03 May 2013 09:00 PM
Someone please help!
Report Abuse
marcusmw331 is not online. marcusmw331
Joined: 07 Jun 2010
Total Posts: 4562
04 May 2013 12:43 AM
:C
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image