Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How does one alter the Axis' on a VectorForce's Attachment?

Asked by 2 years ago

I'm trying to create a lunge/dodge through a VectorForce. I've already written a script that places a VectorForce + Attachment into the player's LowerTorso Whenever I alter the axis(es?) on the attachment, it gives me this error: "X cannot be assigned to". My guess is that it means that you can't alter the attachment through a script. Is there any other way one could go about altering the axis?

        local playerV = Instance.new "VectorForce" -- Creating the vectorForce
        local playerA = Instance.new "Attachment"

        playerV.Parent = Ltorso -- Parenting the vectorForce
        playerA.Parent = Ltorso

        playerV.Attachment0 = playerA -- Attributes for the vectorForce

        playerA.Axis.X = 0 -- Attributes for the attachment
        playerA.Axis.Y = 0
        playerA.Axis.Z = -1
        playerA.SecondaryAxis.X = 0
        playerA.SecondaryAxis.Y = 1
        playerA.SecondaryAxis.Z = 0

1 answer

Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
2 years ago

The error is pretty self-explanatory: you cannot directly manipulate a vector's particular component. For this, you would want to construct a new vector3 with the desired component values:

playerA.Axis = Vector3.new(0, 0, -1)

However, it would be better if you just rotated the attachment using the Attachment's CFrame property, or its WorldCFrame property, because the attachment's CFrame property is relative to its parent's local space, basically it is relative to its cframe; however, WorldCFrame is not relative to the attachment's parent's cframe, but rather, the world space.

For example, the desired rotation you want can be achieved by doing:

playerA.CFrame = CFrame.Angles(0, math.pi/2, 0)
-- math.pi/2 is the amount of radians equivalent to 90 degrees 
-- you could convert your value in degrees to radians using math.rad(deg)

However, the best way to achieve what you want to achieve is by making the force relative to the world, then calculating the direction you want to move in. For example, if you want a force exerted on the player that has a magnitude of 2 in the direction their right side is looking, then you can do either of these:

-- Assuming the variable "HumanoidRootPart" is defined. 
playerV.Force = HumanoidRootPart.CFrame * Vector3.new(2, 0, 0)
-- or:
playerV.Force = HumanoidRootPart.CFrame.RightVector * 2

-- with the force being relative to the world:
playerV.RelativeTo = Enum.ActuatorRelativeTo.World

Just a suggestion, but I would highly recommend using descriptive variable names. playerV doesn't really say that is a vector force, but it can be assumed that is something associated with the player. I would prefer using playerVectorForce or playerForce if you want something shorter, although it shouldn't be ingrained to choose less length over proper description, if the former result is very less descriptive

Ad

Answer this question