- Home /
How do I register damage from the actual sword? not Raycast
Hello I wish to create a small RPG with decent graphics and a cool story-line. But I have come across a road block. I wish to know how you can register damage when the sword hits a enemy not "look in a straight line and register damage before the animation is complete" due to raycast. If you have any way to update my original script to make this happen please tell me (Java Script)
var TheDammage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);`
You can fire a ray from the hilt of the sword (whose length is the blade's length), or you can create a trigger which encompasses the blade. You'd only care about raycast hits or collisions during the attack animations.
Thank you for your input on the matter I an currently trying this out!
Answer by CelticKnight · Aug 17, 2017 at 01:10 AM
Sorry for the lateness on my reply, but, thankyou "AlwaysSunny" for pointing out that the collision needs to be a trigger. I was trying an OnCollisionEnter, which, of course, was not working the way I needed. You also correctly pointed out that the Trigger needed to be only generated during attack animations, due to the way the sword is attached to the characters hand I was getting triggers being generated when ever it got near another object.
This is the problem at hand, with triggers only being generated during an animation that is being generated by the Animator. Going to need some time trying to figure that out.
But thankyou greatly for that information. It has been very helpful!
Your answer
Follow this Question
Related Questions
Trouble with RayCast, rigid body and the colliders tag 0 Answers
Raycasting fail 1 Answer
If Raycast Hits Air 4 Answers
Bomberman like explosion 0 Answers
Accessing colliders, in if statement 2 Answers