using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
private bool canJump = true;
private bool jumping = false;
private Transform head;
// Use this for initialization
void Start () {
head = transform.Find("Chest/Head");
}
// Update is called once per frame
void Update () {
}
// Modifs physiques
void FixedUpdate()
{
Vector3 direction = new Vector3();
direction += Input.GetAxis("Horizontal") * Camera.main.transform.right;
direction += Input.GetAxis("Vertical") * Camera.main.transform.forward;
direction.y = 0;
Vector3 newVelocity = direction * 10;
newVelocity.y = rigidbody.velocity.y;
rigidbody.velocity = newVelocity;
transform.LookAt(transform.position + direction);
rigidbody.angularVelocity = new Vector3();
Vector3 dirGaze = Camera.main.transform.forward;
dirGaze.y = 0;
head.LookAt(head.position + dirGaze);
if (Input.GetButtonDown("Jump") && canJump)
{
rigidbody.AddForce(Vector3.up * 10, ForceMode.Impulse);
canJump = false;
jumping = true;
}
}
void OnCollisionEnter(Collision col)
{
if (col.contacts[0].normal.y > 0.3f)
canJump = true;
}
}
using UnityEngine;
using System.Collections;
public class FollowPlayer : MonoBehaviour {
public Transform trackedObject;
private Vector3 lastPosition;
// Use this for initialization
void Start () {
lastPosition = trackedObject.position;
}
// Update is called once per frame
void FixedUpdate () {
transform.position += trackedObject.position - lastPosition;
lastPosition = trackedObject.position;
transform.RotateAround(trackedObject.position, Vector3.up, Input.GetAxis("HorizontalRight")*3);
transform.RotateAround(trackedObject.position, trackedObject.right, Input.GetAxis("VerticalRight") * 3);
transform.LookAt(trackedObject.position,Vector3.up);
}
}
using UnityEngine;
using System.Collections;
public class Attack : MonoBehaviour {
public Transform grenadePrefab;
Transform gren = null;
float timeThrow = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(gren)
gren.position = Camera.main.transform.position +
Camera.main.transform.forward;
if (Input.GetButton("Fire1"))
{
timeThrow += Time.deltaTime;
if (gren == null)
{
timeThrow = 0;
gren = Instantiate(grenadePrefab,
Camera.main.transform.position +
Camera.main.transform.forward,
Quaternion.identity) as Transform;
}
}
else
{
if (gren != null)
{
Vector3 force = Camera.main.transform.forward;
force = Quaternion.AngleAxis(-30, Camera.main.transform.right) * force;
force = force.normalized * 10 * timeThrow;
Rigidbody rbGren = gren.GetComponent<Rigidbody>();
rbGren.velocity = force;
gren = null;
}
}
}
}