- Home /
Question by
Beansolder · Nov 18, 2017 at 06:49 PM ·
collisionraycastraycasthitrayhit
Fall collision force with help of raycast
Is there a way to implement collision force like this:
I need somehow to get impact value so animation can be played if player hits ground too hard.
using UnityEngine;
using System.Collections;
public class FallCollision : MonoBehaviour {
public float maxForce = 10;
Collision col;
void FixedUpdate()
{
RaycastHit hit;
Ray landingRay = new Ray (transform.position, Vector3.down);
Vector3 fwd = transform.TransformDirection(Vector3.down);
Debug.DrawRay(transform.position, fwd, Color.green);
if(Physics.Raycast(landingRay,out hit, 1)){
if (hit.collider.tag == "Ground"){
print (hit.transform.name);
//this is the part that I am stuck at
if(col.impactForceSum.y >= maxForce){
Debug.Log(col.impactForceSum);
}
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Exclude tag from raycast 1 Answer
Raycasting to detect which side of collider is hit 2 Answers
Need Help with RayCast. No Vector? 1 Answer
Raycast goes through 1 Answer
How to get information from raycast? 2 Answers