Fruit Ninja sword effect

Hey, not sure if this goes here, but, I am looking to produce the same effect that is in fruit ninja, when a player swipes at the screen or moves their fingers around. They produce a knife cut across the screen and I am wondering how I can replicate it both form a coding stand point and from an artistic standpoint. I don’t think I would have trouble with the straight chops but if the player wanted to continually chop in all directions it may be a problem to do.

Any suggestions?

I want to to the same but i don´t know how. Anyone?

Just create an object that’s only alive when the player is pressing and follows the pointer, ie:

if (Input.GetMouseButtonDown (0))
{
    targetObject.SetActiveRecursively (true);
}

if (Input.GetMouseButton (0))
    // Move the "targetObject" to where the mouse/touch was recorded in world space
}

if (Input.GetMouseButtonUp (0))
{
    targetObject.SetActiveRecursively (false);
}

To get the trail effect, there’s no coding required, just use a Trail Renderer.

this is what i’ve found

public class NewBehaviourScript : MonoBehaviour {


	public GameObject yourGameObject;

	void Update () {


		if(Input.GetMouseButton(0))
		{
                          //get mouse possition
			float mousex = (Input.mousePosition.x);
			float mousey = (Input.mousePosition.y);
                           //adapt it to screen
                           // 5 in z to be in the front of the camera, but up to you, just avoid 0
			Vector3 mouseposition = camera.ScreenToWorldPoint(new Vector3 (mousex,mousey,5));
                           //make your gameobject fallow your input
			yourGameObject.transform.position = mouseposition;

		}
	

	}
}

add a trail to your gameobject and work like a charm :slight_smile:
you can adpat the Z value acording to your needs