First person sword fighting

There doesn’t seem to be a step by step tutorial on this can you show me one?

My problem is that I can get my character to hold the sword, but I cant figure out how to make him slash and do damage while still getting the movement controls to work correctly this is the script im using:

var swordPoints : Transform[];
var swingPower : int;
var showGizmosInEditor : boolean = false;


function Update () 
{
    var hit : RaycastHit;
    for(i = 0; i < swordPoints.length; i++)
    {
        if(Physics.Linecast(transform.position, swordPoints*.position, hit))*

{
Hit(swordPoints*, hit);*
}
}
}
function Hit(i : Transform, hit : RaycastHit)
{
if(hit.collider.rigidbody)
{
hit.collider.rigidbody.AddExplosionForce(swingPower, i.transform.position, 1.0, 3.0);
}
if(hit.collider.tag == “Enemy”)
{
hit.collider.gameObject.SendMessageUpwards(“ApplyDamage”, swingPower, SendMessageOptions.DontRequireReceiver);
}
}
function OnDrawGizmosSelected()
{
Gizmos.color = Color.blue;
if(showGizmosInEditor)
{
if(swordPoints.length != 0)
{
for(i = 0; i < swordPoints.length; i++)
{
if(swordPoints != null)
{
Gizmos.DrawLine(transform.position, swordPoints*.position);*
}
}
}
}
}

Agree with the commenters, start by learning analyzing code, and don’t just pick other’s scripts from the internet and expect that they work immediately! :slight_smile:

But I’m going to give you a little help anyway:

Make a script for your sword or add stuff to your movement script. Check if the user presses a button (mouse1 for example), and then make the sword swing using an animation. Then check if there is collision between the sword and the object you want to kill.

Search the scripting reference for all these functions.