Greetings.
So I’m looking for a little guidance here: I’m making a “trip wire”-esque effect in my 2D game.
Using this ability the player clicks on two spots and my code gets both those spots as vector2s. Easy.
From there I’ve been trying to figure out how I would create a tripwire. So far I have a prefab sprite/collider object that I transform/scale/rotate to fit in that spot.
I figure I get the center of those two points ((pointA + pointB)/2) and translate the object there. Scale is the distance between the two points divided by the size of the sprite.
Rotation currently is vector2.angle(pointA, pointB) and here’s where I run into issues.
void DrawTripWire()
{
float angle = Vector2.Angle(pointA, pointB);
tripWireObject.transform.position = (pointA + pointB) /2;
tripWireObject.transform.eulerAngles = new Vector3(0,0,angle);
tripWireObject.transform.localScale = new Vector3( Vector2.Distance(pointA, pointB)/32,0.5f,0);
}
Regardless of pointA or pointB the object always “faces” the same direction. The left side is always lower than the right. regardless of which is input first or anything.
Any advice? Better way of achieving this?
Thanks
-X