GoulstemJoin Date: 2012-07-04 Post Count: 7177 |
So i'm trying to make a telekinesis tool, it uses BodyPosition to move the selected part around.. and it works but there's a problem. I have a conditional statement, where if the mouse's hit position is further away from the specified limit then the position shouldn't go any further away. Now the strangest this is that that bit works, but with the conditional then after it goes past the limit, the position automatically makes the X axis 0 for some unknown reason. I want to know how I can make the new position match up with the mouse's X axis, but still have the Z axis limit. Any ideas? Here's the bit of code for moving the part, all variables are defined and DistanceLimit is 100.
This is a localscript.
Move = (function (Mouse, Obj)
local BodyPosition, CharTorso = Instance.new("BodyPosition",Obj), Plyr.Character.Torso;
BodyPosition.maxForce = Vector3.new(Obj.Size.X*5000,Obj.Size.Y*5000,Obj.Size.Z*5000)
MovingObject = true
while MovingObject do
local mouseHit = Mouse.Hit.p
--[[CONDITIONAL IS HERE]]--
if (mouseHit - CharTorso.CFrame.p).magnitude <= DistanceLimit then
pos = CFrame.new(mouseHit.X,5,mouseHit.Z)
else
--[[THIS IS WHAT'S MESSED UP]]--
pos = (CFrame.new(mouseHit.X,5,0) + Vector3.new(CharTorso.CFrame * CFrame.new(0,0,DistanceLimit)))
-------------------------------------------
end
BodyPosition.position = (pos).p
wait(0.1)
end
MovingObject = false
BodyPosition:Destroy()
end)
|
|
RaybonJoin Date: 2011-07-19 Post Count: 38 |
Consider this a bump and a bit of a suggestion, I'm extremely new to scripting, so I really shouldn't be posting on posts like these, xD
When the "This is what is messed up" code resets the # values, does it break the script? |
|
RaybonJoin Date: 2011-07-19 Post Count: 38 |
Yeah, I have a garbage theory, and it really won't help you, but I think DistanceLimit doesn't allow you to go any further (of course) so it turns the values to 0 because there is nothing defining it further?
Anyone reading this, don't bother making fun of me :D I'm already doing so myself.. |
|
GoulstemJoin Date: 2012-07-04 Post Count: 7177 |
bump, cntkillme chur test 4 novice scripter. |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
'pos = (CFrame.new(mouseHit.X,5,0) + Vector3.new(CharTorso.CFrame * CFrame.new(0,0,DistanceLimit)))'
CFrame in a Vector3 wat :))
Well for 1 you setting z to 0 '(mouseHit.X,5,0)' and trying to add some weird vector thing to it. And you want to constraint it from all axes, not only z.
So maybe something like
_, pos = workspace:FindPartOnRay(
Ray.new(torso.Position, (Vector3.new(mouseHit.X, 5, mouseHit.Z) - torso.Position).unit * DistanceLimit),
character
);
So if it's passed the DistanceLimit, you set it to the "edge" of your circle. You might need to change that a bit but blah |
|
GoulstemJoin Date: 2012-07-04 Post Count: 7177 |
Z isn't the problem, X is. I'm setting Z to 0 then adding Vector3 stuffs, and it works fine. But x always gets set to 0 :( |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
Z and X are both horizontal. You don't want someone to be able to go past their limit just because they are facing a different direction.
Also what are you trying to do here:
'Vector3.new(CharTorso.CFrame * CFrame.new(0,0,DistanceLimit)))' |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
By passed the limit, I mean incorrectly placed :) Not necessarily passed the limit. |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
This is what I think you mean:
prntscr/5obafx
If they go passed the limit, it will place is at the limit. |
|
GoulstemJoin Date: 2012-07-04 Post Count: 7177 |
Yesssssss. So are you saying I have to make the x and z axis relative to the player but extended by the distancelimit? O:: |
|
|
i made this a while ago, dunno if I saved the code
logic is logical |
|
GoulstemJoin Date: 2012-07-04 Post Count: 7177 |
Nevermind, I fixed it:P |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
Did you do this which for some reason didn't think about
CFrame.new(torso.Position, Vector3.new(mouseHit.X, 5, mouseHit.Z)) * CFrame.new(0, 0, -Dist) |
|
GoulstemJoin Date: 2012-07-04 Post Count: 7177 |
Pretty close, yes.
pos = (CFrame.new(CharTorso.Position,mouseHit) * CFrame.new(0,5,-DistanceLimit)) |
|
GoulstemJoin Date: 2012-07-04 Post Count: 7177 |
Award me for being good at something for once cnt.. |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
No, anti-IE ppl suck :)) |
|
GoulstemJoin Date: 2012-07-04 Post Count: 7177 |
w0t about a cookie :)) |
|