|
when i want 1 part to orbit another part I can do something like this:
for i = 1, 360 do
PartB.CFrame = PartA.CFrame * CFrame.Angles(0, i, 0) + PartA.CFrame.lookVector * 5
wait() end
presto, orbit.
but what if I want to simply find a fixed Vector around a part?
Im building a tower defense game and I want my earth tower to launch a boulder at a target, then when the boulder hits its target, the boulder disappears spawning 3 little rocks that arc out in random directions around the Y axis.
The main boulder is no problem and neither is the arcing. its finding the random vectors after it hits that im having issues with. i just dont know how to do it |
|
|
Part = script.Parent
function Find()
local Point = nil
Point = Part.CFrame
* CFrame.Angles(0, math.random(1, 360), 0)
print(Point) end
Find()
That didn't work at all. I kept getting results with 12 numbers
I don't know what that means but I know it's not what I wanted.
I can't post the results either because apparently numbers break roblox's rules. |
|
|
|
|
Have it launch one brick with gyro maybe, then wait(x) and have it clone into two more bricks and have them launch at a different vector? |
|
|
I appreciate that but I'm not looking for suggestions. I already have everything planned out. I'm just looking for help. |
|
|
|
I'm basically trying to do this again:
http://www.roblox.com/Forum/ShowPost.aspx?PostID=145655075
The problem being that I can't find the script now. Idk where I put it and the codepad page is gone. |
|
|
morashJoin Date: 2010-05-22 Post Count: 5834 |
The 12 numbers that your function is printing out is a CFrame. If you do CFrame.lookVector, it will return a Vector3 giving the direction it's facing in radians. |
|
|
|
|
|
|
|
|
|
woot3Join Date: 2008-11-10 Post Count: 3599 |
If the point where the boulder hit is x and I assume that you want to spawn them at a given point around x in a spherical fashion.
function rndNeg()
return math.random(1, 2) == 1 and 1 or -1
end
function getRandomVector(x)
local dir = Vector3.new(math.random()*rndNeg(), math.random()*rndNeg(), math.random()*rndNeg())
return x + dir.unit
end
I believe that'll do it well enough. |
|
|
I'll try to explain this as clear as I can. Apparently I didn't explain it well enough. That's my fault and I take responsibility for that. I blame nobody else.
The boulder is launched in an arc at the target using CFrame, nothing else. An anchored part CFramed at the target. No gyros, no body force.
Once the boulder hits the target, a local variable takes note of the CFrame of the boulder, then deletes it.
This next part is where the help comes in.
Around the Y axis, that means horizontally, flat in a circle. At a set, non changeable distance of 5 studs, 3 random vectors are chosen in this circle around the CFrame that was recorded before the boulder was deleted.
That's what I'm trying to get. Just 3 randomly generated points around the Y axis of the recorded CFrame.
After that it's a simple matter if spawning 3 smaller rocks and arcing them at those points. thats the easy part.
Now, I could use a really UGLY hack where I spawn 3 parts and rotate them using CFrame.Angles and then move them using lookVector, then recording their CFrames, but I would prefer not to use such an ugly workaround. Not to mention the fact that it would take slightly longer to perform the attack if I did that. The animations must run smoothly or else I can't continue building. |
|
|
However, I might be able to work something out using your algorithm. Lemme try something and I'll get right back to ya. |
|
|
Nope, didn't work. It always returns the same point. |
|
woot3Join Date: 2008-11-10 Post Count: 3599 |
Oh, that's easy. Let's assume cf was the CFrame of the boulder and r is how far away the new position is from the center.
local r = 5
local randomPoint = cf * CFrame.Angles(0, math.random()*2*math.pi, 0) * CFrame.new(r, 0, 0)
|
|
|
I've been fooling around with it and it does work, but it seemed a bit confusing to understand until I realized what was going on there.
CFrame.Angles(0, math.random()*2*math.pi, 0)
is no different from
CFrame.Angles(0, math.rad(math.random(1, 360)), 0)
which means I was originally close but I failed to realize I had to extend the distance by adding a CFrame.new after the angles.
Thank you so much. I can get back to building my game now. I don't know why this was so hard. |
|