Commit 453e7b3e authored by g6herbre's avatar g6herbre
Browse files

Merge branch 'master' of https://git.enib.fr/g6herbre/jeu-rev

parents 0960a575 02ea90e7
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollowPlayer : MonoBehaviour
{
public Transform targetObject;
public Vector3 cameraOffset;
// Start is called before the first frame update
void Start()
{
cameraOffset = transform.position - targetObject.transform.position;
}
void LateUpdate()
{
Vector3 newPosition = targetObject.transform.position + cameraOffset;
transform.position = new Vector3(newPosition.x, transform.position.y , transform.position.z);
}
}
fileFormatVersion: 2
guid: d43d48423d69643808d2473cb19a468e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -7,22 +7,40 @@ public class PlayerMovement : MonoBehaviour
// Start is called before the first frame update
public float speed = 1.0f;
public float DeltaTime = 0.5f;
public float jumpForce = 15.0f;
private Rigidbody rb;
private bool canJump = true;
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
/*float movement = Input.GetAxis("Horizontal") * speed;
transform.Translate(movement, 0, 0);*/
if (Input.GetKeyDown(KeyCode.Space) && canJump) {
rb.velocity = new Vector3(rb.velocity.x,jumpForce,rb.velocity.z);
}
if (Input.GetAxisRaw("Horizontal") != 0)
{
Vector3 Newposition = new Vector3(this.transform.position.x + speed * DeltaTime* Input.GetAxisRaw("Horizontal"), this.transform.position.y, this.transform.position.z);
Vector3 Newposition = new Vector3(this.transform.position.x + speed * Time.deltaTime * Input.GetAxisRaw("Horizontal"), this.transform.position.y, 15);
this.transform.position = Newposition;
}
}
void OnCollisionEnter(UnityEngine.Collision other){
if(other.gameObject.tag == "floor" || other.gameObject.tag == "plateform"){
canJump = true;
}
}
void OnCollisionExit(UnityEngine.Collision other){
if(other.gameObject.tag == "floor" || other.gameObject.tag == "plateform"){
canJump = false;
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment