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

[SOLVED] How would I go about detecting if something is to the left or right of a falling part?

Asked by 5 years ago
Edited 5 years ago

So I was trying to make "smarter" bombs by trying to make them move towards a player to help the bomb hit them. I don't got much of an idea of how to do it, or if it's possible. If anybody knows how to do this, please help. Thanks!

Thanks to Fifkee, this question was solved! Thank you!

1 answer

Log in to vote
1
Answered by
Fifkee 2017 Community Moderator Moderation Voter
5 years ago

utilize cframe rightvector and leftvector (leftvector is -rightvector), add the left/rightvector to position and get the between the bomb position and the newly-generated position value via magnitude and shift add the magnitude to the left/right depending if the bomb position is closer to the left/right.

an example of this is for my (broken) camera system:

function isCloserToPosition(p, op, modulofactor)
    p = p.CFrame;
    local p1 = math.abs(((-p.RightVector + p.Position) - op.Position).Magnitude);
    local p2 = math.abs(((p.RightVector + p.Position) - op.Position).Magnitude);

    if (math.floor(p1) > math.floor(p2)) then --if the other part is closer to the right side
        return 'Right', p2/(modulofactor or 1)
    else --if the other part is closer to the left side
        return 'Left', p1/(modulofactor or 1);
    end
end

i add the right and negativerightvector to the position, and then I subtract it from the defender's position. then i check if the first magnitude is greater than the 2nd, if so that means that the 2nd magnitude is closer to the target part (op). then i return 'left' or 'right' depending on the distance magnitude. since the magnitude is the difference between two Vector values, you can easily add/subtract magnitude depending on their relationship to the left/right of the bomb by storing the side that's closest (that's why I use return 'Right', ... and return 'Left', ...)

i think this makes sense, if you have any questions dont be afraid to ask

0
Very interesting. I will test this. LuckyOnes187 39 — 5y
0
modulofactor is there because again, it's simply an example, pure coincidence that I had something that matched your question. Fifkee 2017 — 5y
0
Wait, how exactly would I use this? Bomb, player, what? LuckyOnes187 39 — 5y
0
..you weren't supposed to use my code. read the huge paragraph i sent lol Fifkee 2017 — 5y
View all comments (3 more)
0
No, I get what "p" and "op" is, but "modulofactor" is a new thing used in a new place for me. LuckyOnes187 39 — 5y
0
Or would it be fine to just set modulofactor to 0? LuckyOnes187 39 — 5y
0
Nevermind, it works just fine. LuckyOnes187 39 — 5y
Ad

Answer this question