- Home /
Fps Aiming Script help
can someone help me, either by showing me, or by a link how to get my pistol to aim down sights, i have seen many different one's and none work for me, i have my glock under the glock folder under my first person player thanks
Could you post a specific problem here? We can't really help you unless we know exactly what you want to do, and why other solutions aren't working for you.
Answer by AlanChatham · Sep 22, 2011 at 07:11 AM
Are you trying to get your weapon to fire to the center of the player's camera (i.e. where you would draw the reticle)? This snippet fires a ray from the player's camera straight forward, so it's not actually the weapon firing in that direction, the fire comes straight from the camera.
function Fire(){
var playerCamera = Camera.main;
var hit : RaycastHit;
// Do a raycast forward from the camera to see if we hit a solid object
if (Physics.Raycast (playerCamera.transform.position, direction, hit, range)) {
// Apply a force to any rigidbody we hit
if (hit.rigidbody)
hit.rigidbody.AddForceAtPosition(force * direction, hit.point);
// Send a damage message to the hit object
hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
}
}
Of course, you're probably best off working through that tutorial and seeing everything there yourself - http://unity3d.com/support/resources/tutorials/fpstutorial.html
Good effort, but I think he's trying to create an animation so that the pistol gets raised from a relaxed position (eg while running) to an ai$$anonymous$$g position (where the top of the pistols sort of aligns with the camera, so you get the feeling you're looking down the sights).
That particular effect is probably most easily accomplished by creating it as an animation in whatever modeling application the player character came from, and then playing that animation at the push of a button in Unity.
Answer by fpsteele · Sep 23, 2011 at 11:57 PM
thanks chris, im using blender, but can the animation transfer to unity also? ill try i guess
Your answer
Follow this Question
Related Questions
How To Add A FX When I Teleport. 0 Answers
Zombie FPS 2 Answers
A node in a childnode? 1 Answer