#VectorForce Delay??

1 messages · Page 1 of 1 (latest)

sleek snow
#
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
naive cobalt
#

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?

sleek snow
#

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

naive cobalt
#

I see

#

give me a moment

sleek snow
#

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

naive cobalt
#

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?

sleek snow
#

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

#

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

naive cobalt
#

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

sleek snow
#

ok ill try velocities

naive cobalt
#

let me know how that goes

sleek snow
#
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))

naive cobalt
#

not welded to anything anchored either?

spring jayBOT
#

studio** You are now Level 7! **studio

sleek snow
naive cobalt
#

why is the humanoid there? test with it not there

sleek snow
#

idk

naive cobalt
#

the humanoid can apply a force of its own, best not to mess with it

sleek snow
naive cobalt
#

is the constraint even active then?

#

it might not be active, meaning something is stopping it somewhere

sleek snow
#

no its enabled

naive cobalt
#

enabled and active are two different properties

#

I see that the active box above is unchecked.

sleek snow
#

no i cant modify the active

naive cobalt
#

means that the constraint is trying to work

#

but it's not

sleek snow
#

so i need to switch this to server instead of client?

naive cobalt
#

try it, though I don't think that's the case

#

is the attachment used for anything other than the velocity constraints?

sleek snow
#

so it works

#

but delayed

#

and this time it took longer i wasnt able to record the first half where it wasnt working

naive cobalt
#

revert it back to the client

#

also

sleek snow
#

no this is still client

naive cobalt
#

is the old script still affecting it? is it still using cframes?

sleek snow
#

should i send the entire thing?

naive cobalt
#

you have team create?

#

actually, just send the project

#

I'll have a look right now

sleek snow
#

i think so

#

whats your user

naive cobalt
#

my user is @anumiri

#

may show up as NumerocAbyss408

sleek snow
#

do you want to open the file or for me to add you to team create?

naive cobalt
#

add me on team create

#

if I find a solution I'll explain in real time

sleek snow
#

i sent a request

naive cobalt
#

ok, give me a minute to accept

#

having some technical issues

sleek snow
#

i removed the gravity force because i think gravity should work normally now anyways

#

since im using velocities and not manually updating position

naive cobalt
#

I'm going to be ready in about 7 minutes

sleek snow
#

ok

tidal hornet
#

i have a question.

#

why the fuck are you using self?

naive cobalt
#

self is just the name of a parameter he was using in this problem

sleek snow
#

gave you access

naive cobalt
#

awesome

naive cobalt
#

sorry, internet did my shins in