Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

7 comments

0

Very interesting. I will test this.

0

modulofactor is there because again, it's simply an example, pure coincidence that I had something that matched your question.

0

Wait, how exactly would I use this? Bomb, player, what?

0

..you weren't supposed to use my code. read the huge paragraph i sent lol

0

No, I get what "p" and "op" is, but "modulofactor" is a new thing used in a new place for me.

0

Or would it be fine to just set modulofactor to 0?

0

Nevermind, it works just fine.

This discussion is preserved as it was. New answers, comments, and votes are closed.