Player Controls

This commit is contained in:
Sewmina
2022-06-09 03:05:55 +05:30
parent b0e978fb41
commit 4435d769a6
648 changed files with 136822 additions and 40841 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a164a3dcd856bbf09abadbbe2c75629d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollower : MonoBehaviour
{
public bool autoOffset = true;
public Vector3 offset;
public Transform target;
public float smoothness = 0.1f;
void Start()
{
offset = transform.position - target.position;
}
// Update is called once per frame
void Update()
{
transform.position = Vector3.Lerp(transform.position, target.position + offset, smoothness * Time.deltaTime);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b20032ec7edc76b0ca5b2759bc19363f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class joystick : MonoBehaviour
public class Joystick : MonoBehaviour
{
public bool DissappearOnEnd = true;
private Vector3 defaultPosition;

View File

@@ -0,0 +1,42 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public Transform body;
public float movingSpeed = 0.1f;
public float turningSmoothFactor = 0.1f;
public Joystick joystick;
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
body.Translate(new Vector3(0, movingSpeed), body);
if (joystick.input != Vector2.zero)
{
//Turn
var angle1 = Mathf.Atan2(-joystick.input.y, -joystick.input.x) * Mathf.Rad2Deg;
body.rotation = Quaternion.Lerp(body.rotation, Quaternion.AngleAxis(angle1 + 90, Vector3.forward), turningSmoothFactor * joystick.input.magnitude);
}
}
public float Angle(Vector2 vector2)
{
return 360 - (Mathf.Atan2(vector2.x, vector2.y) * Mathf.Rad2Deg * Mathf.Sign(vector2.x));
}
//Auto assign default variables [Editor only]
void OnValidate()
{
if (body == null)
{
body = transform;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f9292398ab503e2abb1f0dd8acf58f9b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: