Side Scroller Controls

So I’m trying to make something which should be rather simple but I keep finding myself stuck.

What I’m trying to do

Basically I’m trying to make a part that goes up and gets faster and faster. Along with this the Camera follows the part moving up.

Now players can’t control the part going up but they can move it from side to side using S and D however they can’t go past the edges and can’t control the up and down speed. Now when they hit the top it starts them and they’re speed over.

If you happen to know the process I would need to follow to do this or a simple way to do it that’d be great, or even just pointing me in the right direction.

2 Likes

so from what I’ve read that you want the player’s camera to follow the part

try

local TS = game:GetService("TweenService")
local P = game.workspace.Your Parts Name 
local cam = workspace.CurrentCamera 

cam.CameraType = 'Whatever one you want'
cam.Focus = game.workspace.P

local TF = TweenInfo.new(nil, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, nil,nil,nil)



local immaplaythis = TS:Create(TF,PartMove,{Position = Vector3.new(Crazy Number)}


game.Players.PlayerAdded:Connect(function)

immaplaythis:Play()

end)

If you get any errors or anything respond to me and give me the output and script analysis output too.
I’ll try to respond as fast as possible.

signed,
X

1 Like

Not sure what this means.

For detecting S and D, check out UserInputService.InputBegan. And to move it, are you using CFrame or physics constraints?

1 Like

I’m not too sure which would be smoother and more efficient? and hitting the top means when they get to the top of the gray part it would start them over.

Both can be smooth. If the game is multiplayer, then making them physically-based will handle replication automatically. If it’s singleplayer, CFrame is more customizable.

2 Likes

In that case it would seem physically based would be the best way as I intend to have multiplayer in the future. I’ve previously attempted this with body forces and what not but came across a few problems. The first one is that it when applying a force of 1000 to a part 1x1 studs it might move it. But when applying that same force to 5x5 parts it no longer takes effect. Do you happen to know of any way to work around this? Another thing I’ve seemed to encounter is that when when applying a force it seems to get faster and faster on it’s own but I don’t have control over it. And last but not least I can’t seem to figure out how to make it so it goes from side to side using physical parts. Excuse my English

You have discovered Newton’s second law! That is, the force on an object equals its mass times its acceleration or F = m * a. If you want a more massive object to have the same acceleration as a less massive object, you need to apply more force.

Another discovery! Applying a force will increase your velocity over time.

Try using a BodyVelocity instead of a BodyForce if you want to maintain a constant velocity.

UserInputService to detect when the player is pressing S and D which then sets a BodyVelocity to move left/right.

3 Likes

Very helpful. Quick question. how would I increase the Velocity depending by how long they hold down the button and how would I put a cap on how far it can go speed wise from side to side.

If you use a BodyForce, the lower the magnitude, the slower the velocity increases. The higher the magnitude, the quicker the velocity increases. Given a 4x4x4 part and a density of 1, its mass is 4 * 4 * 4 = 64. So if you want the velocity to increase 2 studs per second upward (i.e. an acceleration of 2), the BodyForce.Force would be (0, 64 * 2, 0). If you want the velocity to increase 4 studs per second upward, the BodyForce.Force would be (0, 64 * 4, 0). That’s given that there’s no gravity.

I believe you could check the character’s Velocity property, and if it is over the maximum in the sideways direction, disable the BodyForce.

In general, if you want a constant velocity, use a BodyVelocity. If you want velocity to increase over time, use a BodyForce.

3 Likes

I’ll give this a go. Thank you!