Trouble with making an animatronic movement system

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to make a movement script for bonnie in my fnaf game.

  2. What is the issue? The CAM 3 move in my fnaf bonnie script isn’t working.

  3. What solutions have you tried so far? I analyzed my code for hours and I can’t figure out why it isn’t working

When bonnie is at cam 3, I want him to go back to cam 2a. But when he gets there he doesn’t move even after waiting longer than the random wait interval. I included the whole movement function because I don’t know where the problem is.

local moveableCameras = {
	cam1A = Vector3.new(-12.7, 6.92, -65.9),
	cam1B = Vector3.new(-12, 5.92, -41.4),
	cam2A = Vector3.new(-18, 5.92, -14.7),
	cam2B = Vector3.new(-30.3, 5.92, -7.4),
	cam3 = Vector3.new(-30.3, 5.92, -7.4),
	cam5 = Vector3.new(-34, 5.92, -51.3)
}

local function movement()
	if HRP.Position == moveableCameras.cam1A then
		HRP.Position = moveableCameras.cam1B
		HRP.Orientation = Vector3.new(0, 0, 0)
		wait(math.random(20, 60))
		movement()
	elseif HRP.Position == moveableCameras.cam1B then
		local rng = math.random(1, 2)
		if rng == 1 then
			HRP.Position = moveableCameras.cam5
			HRP.Orientation = Vector3.new(0, -180, 0)
			wait(math.random(20, 60))
			movement()
		elseif rng == 2 then
			HRP.Position = moveableCameras.cam2A
			HRP.Orientation = Vector3.new(0, -180, 0)
			wait(math.random(20, 60))
			movement()
		end
	elseif HRP.Position == moveableCameras.cam2A then
		local rng = math.random(1, 2)
		if rng == 1 then
			HRP.Position = moveableCameras.cam3
			HRP.Orientation = Vector3.new(0, -90, 0)
			wait(math.random(20, 60))
			movement()
		elseif rng == 2 then
			HRP.Position = moveableCameras.cam2B
			HRP.Orientation = Vector3.new(0, 0, 0)
			wait(math.random(20, 60))
			movement()
		end
	elseif HRP.Position == moveableCameras.cam2B then
		wait(math.random(20, 60))
		attack()
	elseif HRP.Position == moveableCameras.cam3 then
		HRP.Position = moveableCameras.cam2A
		HRP.Orientation = Vector3.new(0, -180, 0)
		wait(math.random(20, 60))
		movement()
	elseif HRP.Position == moveableCameras.cam5 then
		HRP.Position = moveableCameras.cam1B
		HRP.Orientation = Vector3.new(0, 0, 0)
		wait(math.random(20, 60))
		movement()
	end
end
1 Like

Does the movement function call bonnie to move? If so how does bonnie know where to move since the function has no parameters?

1 Like

When the movement function is called, it checks where Bonnie is using the moveableCameras table above. If he’s at cam 1B for example, he has two movement options. If he is at cam 3, he has one movement option.

1 Like

Add a print to see if the if statement for cam3 is firing

1 Like

I’ll try that. I’ll let you know if anything

1 Like

Nope, it isn’t firing. (this is my first post and im just talking here in these parentheses bc apparently you need X characters minimum to speak)

I have played FNAF before so where is cam 3 in map?

The map is the same as the actual FNAF. Cam3 is at it’s original spot

If the if statement for camera 3 is never firing, there must either be something wrong with the condition or a previous condition is being met before this if statement.

Here is the Cam 2A statement. If he is at Cam 2A, he has two options. Cam 2B and Cam 3. To determine where he goes, I basically use a coin flip (math.random between 1 and 2). He can only get to Cam 3 from Cam 2A, nowhere else.

elseif HRP.Position == moveableCameras.cam2A then
		local rng = math.random(1, 2)
		if rng == 1 then
			HRP.Position = moveableCameras.cam3
			HRP.Orientation = Vector3.new(0, -90, 0)
			wait(math.random(20, 60))
			movement()
		elseif rng == 2 then
			HRP.Position = moveableCameras.cam2B
			HRP.Orientation = Vector3.new(0, 0, 0)
			wait(math.random(20, 60))
			movement()
		end

Add a print statement in the movement function to see if after it moves to 3 if it is getting a hold up with the wait function.

If you do the print statement and it works you might want to try rewriting the script because I find that if you write it a second time you notice things, you didn’t the first.

I got the print. I’ll just try rewriting the code i guess

Update: I found the problem. CAM 2B and CAM 3 are the same position.

cam2B = Vector3.new(-30.3, 5.92, -7.4),
cam3 = Vector3.new(-30.3, 5.92, -7.4),
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.