Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Spin.cs using System.Collections; using System.Collections.Generic; using UnityEngine; public class SpinScript : MonoBehaviour { public float spinRate = 1 5 f; / / Start is called

Spin.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpinScript : MonoBehaviour
{
public float spinRate =15f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.Rotate(0, spinRate * Time.deltaTime, 0);
}
}
MouseLook.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLook : MonoBehaviour
{
public enum RotationAxes
{
MouseXAndY =0,
MouseX =1,
MouseY =2
}
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityHor =9.0f;
public float sensitivityVert =9.0f;
public float minimumVert =-45f;
public float maximumVert =45f;
private float verticalRot =0f;
// Start is called before the first frame update
void Start()
{
Rigidbody body = GetComponent();
if(body != null)
{
// prevent physics rotations
body.freezeRotation = true;
}
}
// Update is called once per frame
void Update()
{
if (axes == RotationAxes.MouseX)
{
// horizontal rotaiton here
transform.Rotate(0, sensitivityHor * Input.GetAxis("Mouse X"),0);
}
else if (axes == RotationAxes.MouseY)
{
// vertical rotation here
verticalRot -= Input.GetAxis("Mouse Y")* sensitivityVert;
verticalRot = Mathf.Clamp(verticalRot, minimumVert, maximumVert);
float horizontalRot = transform.localEulerAngles.y;
transform.localEulerAngles = new Vector3(verticalRot, horizontalRot, 0);
}
else
{
// horizontal and vertical rotation here
verticalRot -= Input.GetAxis("Mouse Y")* sensitivityVert;
verticalRot = Mathf.Clamp(verticalRot, minimumVert, maximumVert);
float delta = Input.GetAxis("Mouse X")* sensitivityHor;
float horizontalRot = transform.localEulerAngles.y + delta;
transform.localEulerAngles = new Vector3(verticalRot, horizontalRot, 0);
}
}
}
FPSInput.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FPSInput : MonoBehaviour
{
public float speed =3f;
public float gravity =-9.8f;
private CharacterController charController;
// Start is called before the first frame update
void Start()
{
charController = GetComponent();
}
// Update is called once per frame
void Update()
{
//float deltaX = Input.GetAxis("Horizontal")* speed * Time.deltaTime;
//float deltaZ = Input.GetAxis("Vertical")* speed * Time.deltaTime;
//transform.Translate(deltaX,0, deltaZ);
// instead of using the above to move the character, we can simply use the character controller
float deltaX = Input.GetAxis("Horizontal")* speed;
float deltaZ = Input.GetAxis("Vertical")* speed;
Vector3 movement = new Vector3(deltaX,0, deltaZ);
// ensure we don't move too fast
movement = Vector3.ClampMagnitude(movement, speed);
// apply gravity
movement.y = gravity;
// make movement frame dependent
movement *= Time.deltaTime;
// transform from local to global
movement = transform.TransformDirection(movement);
// move charater controller
charController.
Move(movement);
}
}
These are the 3 scripts provided. Please answer the following, will rate up!
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data 29th British National Conference On Databases Bncod 2013 Oxford Uk July 2013 Proceedings Lncs 7968

Authors: Dan Olteanu ,Georg Gottlob ,Christian Schallhart

2013th Edition

3642394663, 978-3642394669

More Books

Students also viewed these Databases questions

Question

2. Are my sources up to date?

Answered: 1 week ago