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

How To Fix A Moving Object Colliding With Other Objects?

Asked by 5 years ago

To start of, I am new to scripting, and not sure what is happening. I have a WW2 Plane Mesh I inserted. The script lets you click on the canopy, it then moves from its "start position" to the new given position. The "canopy" is the part of the plane that slides back to let you sit down. When I tested it, it collided with another part of the mesh and got pushed/moved up. When you click it, it stays at the same height, and moves back to the "start position." I tried turning off CanCollide and nothing seems to work. I cant figure it out.

Is there any way to make it so it goes to the set location without being raised, or hitting other meshes/parts?

open = true
Part = script.Parent
Model = game.Workspace.Model.Canopy

Part.ClickDetector.MouseClick:Connect(function()
    if open==true
    then
        open=false
        Model:MoveTo(Vector3.new(3.741, 11.572, -5.2))
    else
        open=true
        Model:MoveTo(Vector3.new(0.741, 11.562, -5.2))
    end
end)

https://gyazo.com/95ff30699370657aa7ebfb3914d90420 https://gyazo.com/1903bfe718cce649ff96239ec167941f https://gyazo.com/2d1d7339732c387074c159367858ed47

Thanks, GIennMiller.

1 answer

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

The reason this is happening is because when you change a part/model's position, MoveTo changes the position, the game will make sure things don't overlap, we can't stop this by changing CFrame instead.

Lets use the :SetPrimaryPartCFrame() function to move/orientate the models

First make sure your model has a PrimaryPart set

Before you set the model's parent, use the function to set its position

We can change its orientation using CFrame.Angles() CFrame.Angles uses something called radians. You may be more known with the term degrees instead, roblox gives us a way to easily change degrees to radians without us having to math using math.rad(degrees)

local model=model
--position and orientation
local cf=CFrame.new(0,0,0)*CFrame.Angles(0,math.rad(90),0)

--setprimarypartcframe take a cframe value which is applied to the model's primarypart
--the other parts are moved along with the primarypart
model:SetPrimaryPartCFrame(cf)

So assuming the model has a PrimaryPart

open = true
Part = script.Parent
Model = game.Workspace.Model.Canopy

Part.ClickDetector.MouseClick:Connect(function()
    if open==true then
        open=false
        Model:SetPrimaryPartCFrame(CFrame.new(3.741, 11.572, -5.2))
    else
        open=true
        Model:SetPrimaryPartCFrame(CFrame.new(0.741, 11.562, -5.2))
    end
end)

If the model has Anchored false and CanCollide true, you may still need to do some adjusting such as making thing CanCollide false.

0
if open then open = not open WikiBaseHealthFinder 40 — 5y
Ad

Answer this question