You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
Ive recently been making a sonic character controller (currently dont have jumping, or wall collision) but I have floor collisions, movement and slope alignment. Only problem, I want to create momentum/inertia when on slopes (i.e, having the character slide down when speed is too slow)
-
What is the issue? Include screenshots / videos if possible!
I don’t necessarily know how to go about doing this, as I lack experience or the knowledge to do so. Im not asking anybody to make this for me, But i would greatly appreciate it if somebody could help point me in the right direction at least. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
There are currently no solutions on the dev hub, and I’ve looked a lot of places for help I’m not sure what it is I’m supposed to be doing. Sorry if it’s a bit messy but here’s my code.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
--
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local HRP = Character:WaitForChild("HumanoidRootPart")
Character.Parent = RS
local MoveDirection = Humanoid.MoveDirection
local lastMoveDirection
local Sonic = Instance.new("Model",workspace)
Sonic.Name = "Character"
local Hitbox = Instance.new("Part",Sonic)
Sonic.PrimaryPart = Hitbox
Hitbox.Size = Vector3.new(0.25,5,0.25)
Hitbox.Position = Vector3.new(0,20,0)
Hitbox.CanCollide = false
Hitbox.CanQuery = false
--
local rParams = RaycastParams.new()
rParams.FilterType = Enum.RaycastFilterType.Exclude
rParams.FilterDescendantsInstances = {Character,Sonic}
local raycast
local lastNormal = nil
local Align = Instance.new("AlignOrientation",Hitbox)
Align.Attachment0 = Instance.new("Attachment",Hitbox)
Align.Mode = Enum.OrientationAlignmentMode.OneAttachment
Align.Responsiveness = 50
local bv = Instance.new("BodyVelocity",Hitbox)
bv.MaxForce = Vector3.new(99999,99999,99999)
bv.Velocity = Vector3.new()
local Camera = workspace.CurrentCamera
Camera.CameraSubject = Hitbox
--
local Groundspeed = 0
local ySpeed = 0
local AirSpeed = 0
local Angle = 0
local Direction = 0
local groundVector = Vector3.zero
local upVector = Vector3.zero
--
----
local c1 = coroutine.create(function()
local function _()
MoveDirection = Humanoid.MoveDirection
Angle = math.deg(math.acos(Hitbox.CFrame.UpVector:Dot(Vector3.new(0,1,0))))
groundVector = Hitbox.CFrame.LookVector
if MoveDirection.Magnitude > 0 then
Align.CFrame = CFrame.lookAlong(Hitbox.Position,Vector3.new(0,1,0):Cross(MoveDirection):Cross(Hitbox.CFrame.UpVector),Hitbox.CFrame.UpVector)
lastMoveDirection = MoveDirection
end
if Vector3.yAxis:Dot(Hitbox.CFrame.LookVector) < 0 then
Direction = -1
else
Direction = 1
end
if Humanoid.MoveDirection.Magnitude > 0 then
Groundspeed += 0.4
if Groundspeed > 40 then
Groundspeed = 40
end
else
Groundspeed -= 0.6
if Groundspeed < 0 then
Groundspeed = 0
end
end
return
end
while game:GetService("RunService").Heartbeat:Wait() do
_()
end
end)
local c2 = coroutine.create(function()
local function _()
raycast = workspace:Raycast(Hitbox.Position + Hitbox.CFrame.UpVector * 2.5,Hitbox.CFrame.UpVector * (-5 - Hitbox.Velocity.Magnitude/10),rParams)
if raycast then
if lastNormal ~= raycast.Normal then
lastNormal = raycast.Normal
bv.Velocity = Vector3.new()
end
Hitbox.Position = raycast.Position + Hitbox.CFrame.UpVector * 2.5
Hitbox.CFrame = CFrame.fromMatrix(Hitbox.Position,Hitbox.CFrame.LookVector:Cross(raycast.Normal),raycast.Normal,Hitbox.CFrame.RightVector:Cross(raycast.Normal))
ySpeed = 0
else
if lastNormal ~= nil then
lastNormal = nil
bv.Velocity = Vector3.new()
end
ySpeed -= 0.6
Hitbox.CFrame = CFrame.fromMatrix(Hitbox.Position,Hitbox.CFrame.LookVector:Cross(Vector3.new(0,1,0)),Vector3.new(0,1,0),Hitbox.CFrame.RightVector:Cross(Vector3.new(0,1,0)))
end
upVector = Vector3.new(0,1,0)
bv.Velocity = (groundVector * Groundspeed) + (upVector * ySpeed)
return
end
while game:GetService("RunService").Heartbeat:Wait() do
_()
end
end)
coroutine.resume(c1)
coroutine.resume(c2)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.