Screw what I said in the video, just post your glitches and questions in this thread.
Be sure so scroll through other people’s posts here; Someone else might have had the same problem as you, or you may find someone who is having a problem that you figured out last week.
I will still personally try to respond and help everyone with whatever problems they are having, and I think I will be able to do this more effectively on the forums.
How about a tutorial on how to create a first-person camera conversion to third person camera. Using the scroll wheel to move between them or automated for “cut” sequences?
Two Issues: My variables for the gun’s position were screwed up and when I added the rest of the code the gun changes position on the z axis when I look up/down. PLEASE HELP
What video covers the UseKey script, which supposedly is in the video dealing with picking up guns?. A video I haven’t been able to find. Quick help would be much appreciated, as I’m kind of on a deadline here and this one little thing is hanging me up.
My gun has sort of a jittering motion? If that makes sense. The gun jumps left and right slightly when I rotate the screen and it does it more profusely when I move forward and rotate. And I skipped 1.23 and went to 1.24 because I wanted to do some stuff but didn’t have enough time for a long vid, so I did 1.24 and then did 1.23
EDIT: Also I didn’t add the script because I don’t think it has to do with my script. I will if you tell me to. And changing the layer from guns doesn’t change anything
I have a generic question, of something I noticed while using my imported gun model.
For some reason, when I am zoomed out the Raycast is not centered on screen. At least, that’s what I think as the bulletHole object gets created off center to the right.
When aiming it’s all perfect. It lines up perfectly with the gun. Just as soon as I am zoomed out the bullets are offset to the side.
Is this something I can fix in code? Or something that I have to fix in the Inspector?
I have my gun’s local coordinates at x: 0, y: 0, and z: 0.75.
Hi ETeeski,
first thank you very much for these instructive tutorilas. In FPS1.11, I’d like to understand why we use - as in other parts of the code - both smoothDamp and Lerp to get a smooth transition. ¿Wouldn’t be enough to smoothDamp between both camera FOVs?
My thread: http://forum.unity3d.com/threads/129959-FPS1.11-ETeeski-Tutorials
Another generic Gameplay question: When pressing both A+S or A+W or D+S or D+W (ergo: Horizontal Vertical movement at the same time) the character walks diagonally at twice the speed it is allowed to move, even though the maxWalkSpeed is set.
Is there a way to always limit the movement speed to maxWalkSpeed? Even if multiple keys are pressed?
Hey,
For my character he is using a capsule collider and rigid body for a movement motor.
i know you have a tutorial for stairs but that doesn’t apply for the capsule collider and rigid body.
Is there any way to edit the following script to create like a step offset?
var crouchSpeed = 2.0;
var walkSpeed = 8.0;
var runSpeed = 20.0;
var fallDamageMultiplier : int = 2;
var fallAnimGO : GameObject;
var inAirControl = 0.1;
var gravity = 20.0;
var maxVelocityChange = 10.0;
var canJump = true;
var jumpHeight = 2.0;
var fallSound : AudioClip;
var playerWeapons : GameObject;
var grounded = false;
private var sliding : boolean = false;
private var speed = 10.0;
private var limitDiagonalSpeed = true;
private var crouching : boolean;
private var normalHeight : float = 0.5;
private var crouchHeight : float = -0.2;
private var crouchingHeight = 0.3;
private var hit : RaycastHit;
private var myTransform : Transform;
private var rayDistance : float;
private var mainCameraGO : GameObject;
private var weaponCameraGO : GameObject;
@script RequireComponent(Rigidbody, CapsuleCollider)
function Awake (){
rigidbody.freezeRotation = true;
rigidbody.useGravity = false;
myTransform = transform;
mainCameraGO = gameObject.FindWithTag("MainCamera");
weaponCameraGO = gameObject.FindWithTag("WeaponCamera");
rayDistance = collider.height * .5 + collider.radius;
playerWeapons.animation.wrapMode = WrapMode.Loop;
}
function FixedUpdate (){
if (grounded){
var inputX = Input.GetAxis("Horizontal");
var inputY = Input.GetAxis("Vertical");
var inputModifyFactor = (inputX != 0.0 inputY != 0.0 limitDiagonalSpeed)? .7071 : 1.0;
if (Physics.Raycast(myTransform.position, -Vector3.up, hit, rayDistance)) {
if (Vector3.Angle(hit.normal, Vector3.up) > 30){
sliding = true;
rigidbody.AddRelativeForce (-Vector3.up * 500);
}else{
sliding = false;
}
}
// Calculate how fast we should be moving
var targetVelocity = new Vector3(inputX * inputModifyFactor, 0.0, inputY * inputModifyFactor);
targetVelocity = myTransform.TransformDirection(targetVelocity);
targetVelocity *= speed;
// Apply a force that attempts to reach our target velocity
var velocity = rigidbody.velocity;
var velocityChange = (targetVelocity - velocity);
velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
velocityChange.y = 0;
rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);
if (canJump Input.GetButton("Jump")){
rigidbody.velocity = Vector3(velocity.x, CalculateJumpVerticalSpeed(), velocity.z);
}
if(!crouching){
if (grounded Input.GetButton("Run") Input.GetKey("w"))
speed = runSpeed;
else
speed = walkSpeed;
}else{
speed = crouchSpeed;
}
}else{
// AirControl
targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
targetVelocity = transform.TransformDirection(targetVelocity) * inAirControl;
rigidbody.AddForce(targetVelocity, ForceMode.VelocityChange);
}
// Gravity
rigidbody.AddForce(Vector3 (0, -gravity * rigidbody.mass, 0));
grounded = false;
}
function OnCollisionStay (col : Collision){
if (Physics.Raycast(myTransform.position, -Vector3.up, hit, rayDistance)) {
grounded = true;
}
}
function HitJumpPad(velocity: float) {
rigidbody.velocity.z += velocity;
}
function OnCollisionEnter (collision : Collision){
if(!grounded){
fallAnimGO.animation.CrossFadeQueued("Fall", 0.3, QueueMode.PlayNow);
var currSpeed : float = collision.relativeVelocity.magnitude;
if (currSpeed > 20) {
var damage : float = currSpeed * fallDamageMultiplier;
Debug.Log ("FallDamage" + damage);
SendMessage ("PlayerDamage", damage, SendMessageOptions.DontRequireReceiver);
}
}
}
function CalculateJumpVerticalSpeed (){
return Mathf.Sqrt(2 * jumpHeight * gravity);
}
function Update(){
if (grounded rigidbody.velocity.magnitude < (walkSpeed+2) rigidbody.velocity.magnitude > (walkSpeed-2) !Input.GetButton("Fire2")){
playerWeapons.animation.CrossFade("Walk");
}else if (grounded rigidbody.velocity.magnitude < (runSpeed+2) rigidbody.velocity.magnitude > (runSpeed -2)){
playerWeapons.animation.CrossFade("Run");
}else if (grounded rigidbody.velocity.magnitude < (crouchSpeed+1) rigidbody.velocity.magnitude > (crouchSpeed-1) Input.GetButton("Fire2"))
playerWeapons.animation.CrossFade("CrouchAim");
else
playerWeapons.animation.CrossFade("IdleAnim");
if(mainCameraGO.transform.localPosition.y > normalHeight){
mainCameraGO.transform.localPosition.y = normalHeight;
} else if(mainCameraGO.transform.localPosition.y < crouchHeight){
mainCameraGO.transform.localPosition.y = crouchHeight;
}
if(weaponCameraGO.transform.localPosition.y > normalHeight){
weaponCameraGO.transform.localPosition.y = normalHeight;
} else if(weaponCameraGO.transform.localPosition.y < crouchHeight){
weaponCameraGO.transform.localPosition.y = crouchHeight;
}
if (Input.GetButtonDown("Crouch") !crouching) {
collider.height = 1.5;
collider.center = Vector3 (0, -0.25, 0);
crouching = true;
}
if(Input.GetButtonUp("Crouch") crouching){
collider.height = 2.0;
collider.center = Vector3 (0, 0, 0);
crouching = false;
}
if(crouching){
if(mainCameraGO.transform.localPosition.y > crouchHeight){
if(mainCameraGO.transform.localPosition.y - (crouchingHeight * Time.deltaTime/.1) < crouchHeight){
mainCameraGO.transform.localPosition.y = crouchHeight;
} else {
mainCameraGO.transform.localPosition.y -= crouchingHeight * Time.deltaTime/.1;
}
}
if(weaponCameraGO.transform.localPosition.y > crouchHeight){
if(weaponCameraGO.transform.localPosition.y - (crouchingHeight * Time.deltaTime/.1) < crouchHeight){
weaponCameraGO.transform.localPosition.y = crouchHeight;
} else {
weaponCameraGO.transform.localPosition.y -= crouchingHeight * Time.deltaTime/.1;
}
}
} else {
if(mainCameraGO.transform.localPosition.y < normalHeight){
if(mainCameraGO.transform.localPosition.y + (crouchingHeight * Time.deltaTime/.1) > normalHeight){
mainCameraGO.transform.localPosition.y = normalHeight;
} else {
mainCameraGO.transform.localPosition.y += crouchingHeight * Time.deltaTime/.1;
}
}
if(weaponCameraGO.transform.localPosition.y < normalHeight){
if(weaponCameraGO.transform.localPosition.y + (crouchingHeight * Time.deltaTime/.1) > normalHeight){
weaponCameraGO.transform.localPosition.y = normalHeight;
} else {
weaponCameraGO.transform.localPosition.y += crouchingHeight * Time.deltaTime/.1;
}
}
}
}
function Accelerate (accelerateY : float, accelerateZ : float){
grounded = false;
rigidbody.AddRelativeForce (0, accelerateY, accelerateZ);
}