self.GravityForce = Instance.new("VectorForce")
self.Attachment = Instance.new("Attachment")
self.Attachment.Parent = self.Root
self.GravityForce.Parent = self.Root
self.GravityForce.Force = Vector3.new(0, -40000, 0)
self.GravityForce.Attachment0 = self.Attachment
self.GravityForce.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
#VectorForce Delay??
1 messages · Page 1 of 1 (latest)
I'm thinking there's some other code that is interfering with the part's position/anchored properties.
I think I need more details. what are you trying to achieve?
just playing around with custom characters
local states = {
Forward = {Active = false, Direction = "LookVector", Adjustment = 1, KeyCode = Enum.KeyCode.W},
Backward = {Active = false, Direction = "LookVector", Adjustment = -1, KeyCode = Enum.KeyCode.S},
Left = {Active = false, Direction = "RightVector", Adjustment = -1, KeyCode = Enum.KeyCode.A},
Right = {Active = false, Direction = "RightVector", Adjustment = 1, KeyCode = Enum.KeyCode.D},
Up = {Active = false, Direction = "UpVector", Adjustment = 1, KeyCode = Enum.KeyCode.Space}
} :: {[string]: State}
function Character.ActivateMovement(self : Character)
RunService.Heartbeat:Connect(function()
for _, state in states do
if state.Active then
self.Root.Position += self.Root.CFrame[state.Direction] * speed * state.Adjustment
end
end
end)
UserInputService.InputBegan:Connect(function(input, gpe)
if gpe then
return
end
for _, state in states do
if state.KeyCode == input.KeyCode then
state.Active = true
end
end
end)
UserInputService.InputEnded:Connect(function(input, gpe)
if gpe then
return
end
for _, state in states do
if state.KeyCode == input.KeyCode then
state.Active = false
end
end
end)
end
speed is 0.12 because its in a runservice loop
if youre overwhelmed this is the position modifying part
RunService.Heartbeat:Connect(function()
for _, state in states do
if state.Active then
self.Root.Position += self.Root.CFrame[state.Direction] * speed * state.Adjustment
end
end
end
state.Direction is lookvector rightvector upvector
adjustment is positive 1 or negative 1 depending on direction
active becomes true once the key is pressed
oddly enough collisions dont register even though cancollide is toggled as well
its like the physics are delayed when you update the players character
it could be because im doing this on the client but i assumed thats how it should be done
because i reference current camera
to update the rotation of the part based on the y value of the cameras rotation
if you constantly input something with this system, every frame the CFrame gets overwritten.
that constant overwriting of the CFrame "delays physics" because you are constantly setting position. CFrame is not physics dependent, so until you stop inputting, the root's position won't be affected by physics.
test this:
does physics seem to work when you stop inputting?
it does but also when i am inputting
let me send two more videos hold on
ok so when im not making input it keeps me there
but when i move my mouse while holding right click to turn my camera
then it works
but not immediately when i join the game
example when i moved my camera
example when im not moving my camera
ok so i think i know whats going on
RunService.Heartbeat:Connect(function()
local _, y, _ = self.Camera.CFrame:ToOrientation()
local goalCFrame = CFrame.new(self.Root.Position) * CFrame.Angles(0, y, 0)
self.Root.CFrame = goalCFrame
end)
this line of code
but i need to update my rotation while maintaining my position
so how can i do that without interfering with the vector force
like lets say im on the ground, i should be able to turn and rotate at the current position, but when i press space and move myself a few studs into the air, i should be pulled down by the vector force, but i should also still be able to turn my camera and rotate the character
because if i removed position then the default would be CFrame.new(0, 0, 0) * that rotation
im pretty sure
do you think what i need to do is limit the updating of rotation to right mouse button press and releases, instead of using a general runservice loop
CFrame, no matter what the circumstances, will always supercede physics so gravity is harder te implement. you get a sort of "reinventing the wheel" situation.
if you want this character to be physically simulated, then CFrame movement is not really the way to go.
I suggest using these two constraints:
LinearVelocity
Angular velocity.
limiting updates won't work because while physics will be able to run in between CFrame updates, the CFrame updates are abrupt and therefore look jittery
ok ill try velocities
let me know how that goes
RunService.Heartbeat:Connect(function()
local baseDirection = Vector3.zero
for stateName, state in states do
if state.Active then
baseDirection += self.Root.CFrame[state.Direction] * state.Adjustment
end
end
self.MovementForce.VectorVelocity = baseDirection * speed
end)
it did not work as you can see
part isnt anchored or anything either
vector force is negative gravity (Vector3.new(0, -workspace.Gravity, 0))
not welded to anything anchored either?
** You are now Level 7! **
nope
why is the humanoid there? test with it not there
idk
the humanoid can apply a force of its own, best not to mess with it
still nothing
is the constraint even active then?
it might not be active, meaning something is stopping it somewhere
enabled and active are two different properties
I see that the active box above is unchecked.
no i cant modify the active
so i need to switch this to server instead of client?
try it, though I don't think that's the case
is the attachment used for anything other than the velocity constraints?
just the vector force linear velocity and angular velocity
again its being delayed
so it works
but delayed
and this time it took longer i wasnt able to record the first half where it wasnt working
no this is still client
is the old script still affecting it? is it still using cframes?
should i send the entire thing?
do you want to open the file or for me to add you to team create?
i sent a request
i removed the gravity force because i think gravity should work normally now anyways
since im using velocities and not manually updating position
I'm going to be ready in about 7 minutes
ok
self is just the name of a parameter he was using in this problem
gave you access
awesome
sorry, internet did my shins in