- Home /
Question by
Leonard-Walker · Feb 04, 2013 at 07:52 AM ·
movementraycastinggrappling gun
Grappling hook gun -- problem moving player?
This is what I have managed to find so far towards getting a working solution, The part I can not figure out how to get working, is moving the player from point a to point be over a given time so that the player is moving to the raycast hit point.
.
// Raycast up to 100 meters forward
var GrapplingHitPoint;
var smooth = 5.0;
function Update()
{
if(Input.GetButtonDown("Fire1"))
{
FireGrapple();
}
}
function FireGrapple ()
{
var hit : RaycastHit;
if (Physics.Raycast (transform.position, Vector3.forward, hit, 100.0))
{
GrapplingHitPoint = hit.point;
print("Hit Something");
}
Debug.DrawLine (Vector3.zero, Vector3 (1, 0, 0), Color.red);
}
//Pulls Me to the target position like a spring
function GrappleMeToPoint()
{
transform.position = Vector3.Lerp (transform.position, GrapplingHitPoint,Time.deltaTime * smooth);
}
Comment
consider unityGE$$anonymous$$S.com for basic articles on transform, moving, lerp, rigidbody, etc.