- Home /
Other
Create arrow to show force and direction
I am trying to create a line render that can be pulled back to a max length and has a max rotation. The idea is when you pull back on the "thrower" an arrow will appear where you are dragging to show shot strength and direction when released an object will spawn and be fired in that direction with the appropriate force.
Answer by Vilhien · May 02, 2018 at 12:40 AM
If you track your input position of your mouse/finger loc with a transform in the same spot maybe.. (pullinput.transform).LookAt(centerhingethrower.position); running constantly would make the invisible transform always point towards the center, then, arrow.rotation=pullinput.rotation The arrow sprite/etc can mimic that same rotation to be pointing in the direction that pulled input is facing (IE your trajectory). The distance of the input of the puller could always change the sprite color based off of a min and max.
That's my idea at least, best of luck!
@Vilhien I have a line render that can only be pulled back to a max stretch and I set a max rotation for the "thrower" but I don't know how to define a rotation limit for the line render because its not being rotated its just a line between two points.
void Dragging(){
Vector3 mouseWorldPoint = Camera.main.ScreenToWorldPoint (Input.mousePosition);
Vector2 throwerTo$$anonymous$$ouse = mouseWorldPoint - this.transform.position;
rayTo$$anonymous$$ouse.direction = throwerTo$$anonymous$$ouse;
if(throwerTo$$anonymous$$ouse.sqr$$anonymous$$agnitude > maxStretchSqr)
mouseWorldPoint = rayTo$$anonymous$$ouse.GetPoint (maxStretch);
mouseWorldPoint.z = 0f;
Quaternion q = Quaternion.FromToRotation(this.transform.position, rayTo$$anonymous$$ouse.direction);
Vector3 v3Euler = q.eulerAngles;
if (v3Euler.z > maxRotation && v3Euler.z <= 180f)
v3Euler.z = maxRotation;
else if (v3Euler.z < $$anonymous$$Rotation && v3Euler.z > 180f)
v3Euler.z = $$anonymous$$Rotation;
powerLine.SetPosition (1, mouseWorldPoint);
this.transform.eulerAngles = v3Euler;
}
Dragging is called every frame when clicked on the "thrower".