My issue is that the RotationX and RotationY variables are not updated with it, and I do not know how to extrapolate it from a Quaternion. As a result, when I let go of the Lock-On button, the camera snaps back to the ‘last’ position, which is not the behavior I desire.
Can you post the exact error? (The problem may be that you have a function other than a constructor with the same name as the class to which it belongs.)
Assets/Standard Assets/Camera Scripts/MouseLook.cs(46,33): error CS0246: The type or namespace name `FindClosestEnemy’ could not be found. Are you missing a using directive or an assembly reference?
On my First Person Controller GameObject, I have two scripts: MouseLook.cs, and FindClosestEnemy.js. I wish to use FindClosestEnemy in MouseLook, hence the line:
I need to be able to ‘draw’ lines across the screen and translate it to the world space. Currently I have such code:
var direction = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
// Did we hit anything?
if (Physics.Raycast (transform.position, direction, hit, range)) {
// Apply a force to the rigidbody we hit
if (hit.rigidbody)
hit.rigidbody.AddForceAtPosition(force * direction, hit.point);
// Place the particle system for spawing out of place where we hit the surface!
// And spawn a couple of particles
if (hitParticles) {
hitParticles.transform.position = hit.point;
hitParticles.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
hitParticles.Emit();
}
// Send a damage message to the hit object
hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
}
Which was taken from the FPS tutorial’s Machine Gun example. What I would like to be able to do is to make the raycast point at wherever the mouse is pointing rather than Vector3.forward. I’ve taken a look at ScreenPointToRay but I cannot seem to get it to work, because I do not have a camera object…[/code]
There’s an example of how to use a raycast from the camera here. If you can see anything in the scene, then you must have a camera somewhere. It is probably the main camera that is in the scene by default. You can access it from a script using Camera.main.
Thank you very much for that, that worked wonderfully.
The next step I am uncertain about is how to create a ‘beam’; I wish to create a ‘melee’-effect with the Particle Emitter, similar to how a laser sword or some other type of drawn line would behave.
Using the particle system is fairly straightforward, but you will probably have to experiment a bit to get the exact effect you want. Try using the Particles/Additive shader for the particle material. You can make them emit from a single line using an ellipsoid emitter, but with the ellipsoid set so that two of the axes are set to zero. (For example, set the ellipsoid’s X and Z components to zero to emit along the Y axis.) You will probably want to use a high emission rate and low energy (probably less than 0.5) to leave a slight trail without having a cloud of particles hanging around.
I am having trouble getting a grasp of when to enable my LineRenderer and when to turn it off.
I would like to have the effect appear when the user presses the Fire1 button, and make it go away when he releases it. Where would I put the linerender.enabled = true and false?
Alright; so I have a script that essentially is a melee weapon – it uses a LineRenderer object that is set to enabled = true when the player presses the Fire1 button.
I’ve tried several things, but I am not able to consistently turn it off when it’s done – I’ve tried putting it in LateUpdate and Update, but it isn’t guaranteed that the renderer will be disabled every time I release the button.