Added camera tracking and movement
This commit is contained in:
21
Assets/Scripts/CameraTracking.cs
Normal file
21
Assets/Scripts/CameraTracking.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraTracking : MonoBehaviour
|
||||
{
|
||||
public Transform player;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
Vector3 playpos = player.transform.position;
|
||||
playpos.z = playpos.z - 10;
|
||||
transform.position = playpos;
|
||||
}
|
||||
}
|
11
Assets/Scripts/CameraTracking.cs.meta
Normal file
11
Assets/Scripts/CameraTracking.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f3d4f7e2abaa2249bfa4476927789a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
34
Assets/Scripts/PlayerControls.cs
Normal file
34
Assets/Scripts/PlayerControls.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerControls : MonoBehaviour
|
||||
{
|
||||
public Rigidbody2D rb;
|
||||
public CircleCollider2D circ;
|
||||
public LayerMask LVLMask;
|
||||
public float walking_speed;
|
||||
public float jump_power;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
float speed = Input.GetAxisRaw("Horizontal") * Time.deltaTime;
|
||||
Vector2 movement = new Vector2(0, 0);
|
||||
movement.x = walking_speed * speed;
|
||||
|
||||
if (Input.GetButtonDown("Jump") || Input.GetAxisRaw("Vertical") > 0)
|
||||
{
|
||||
if (circ.IsTouchingLayers(LVLMask)){
|
||||
movement.x = movement.x / 10;
|
||||
movement.y = jump_power;
|
||||
}
|
||||
}
|
||||
rb.AddRelativeForce(movement);
|
||||
}
|
||||
}
|
11
Assets/Scripts/PlayerControls.cs.meta
Normal file
11
Assets/Scripts/PlayerControls.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18f3e7f51c3b5da4090d81c28486d6dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user