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

Is it possible to run tween and velocity simutaniously?

Asked by 4 years ago

Some background to the code that is not included: the code welds the player and spaceship (a union part) together. The code is supposed to keep the spaceship pointing where the mouse is pointing. The problem is that is the tween service is blocking the velocity or is there another problem.

Here is the code:

while true do
     wait(0.1)
    local bodyPart =  player.Character:FindFirstChild("LowerTorso")
    local goals = {CFrame = CFrame.new(bodyPart.Position, 
    Vector3.new(mouse.Hit.X, mouse.Hit.Y * 2, mouse.Hit.Z))}
    local tween = ts:Create(p, info, goals)
    tween:Play()


    game:GetService("UserInputService").InputBegan:connect(function (input, _) -- recognizes input is being given
        if input.KeyCode == Enum.KeyCode.E then 
            y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
            y.velocity = (p.Position - mouse.hit.p).unit * 175
            print("done")
        end
    end)        
end

Thanks for the Help!

1 answer

Log in to vote
0
Answered by 4 years ago

You should not be using a while loop for this task at all as it will lead to stuttery movements. In addition you are connecting a new function to the InputBegin event every loop which is not needed.

For this kind of work you want to be using the RunService.

I would also look at using the following constraints as they are more flexible in general.


You should be setting the expected rotation and directional force on frame render to get a smooth result.

Make sure to set the network ownership this will pass the physics calculation load from the server to the players device. This means they will see the changes first as they are the ones calculating it. Note this does however mean that this can be expoited as the client can now change the physics as will e.g. teleport around the map.

Overall its a trade off between gameplay and game security but you can use sanity checks to help reduce expoitability.

I hope this helps. Please comment if you have any questions related to this post.

0
Can you give me an example code or something awesomemode14 68 — 4y
0
I would reviw the code and make any changes to the way you are attempting to solve this. Then post a new question if you have any other issues. User#5423 17 — 4y
0
The dev hub api pages include example of how each constraint can be used. User#5423 17 — 4y
Ad

Answer this question