mirror of
https://github.com/appen-isen/jeu-sans-image.git
synced 2026-03-18 21:50:42 +01:00
added basic controls
Added a player with basic movement/rotation controls. Uses default Input Actions, so most controllers should work.
This commit is contained in:
8
Assets/Scripts/Control.meta
Normal file
8
Assets/Scripts/Control.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4c053d580b26d14ab03dc9a21f90ee3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
58
Assets/Scripts/Control/PlayerController.cs
Normal file
58
Assets/Scripts/Control/PlayerController.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using UnityEngine;
|
||||
|
||||
// Handles everything related to player movement
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
private PlayerControlsMap playerControls;
|
||||
private Rigidbody rb;
|
||||
|
||||
[SerializeField] private float speed = 15;
|
||||
[SerializeField] private float sensitivity = 50;
|
||||
[SerializeField] private float maxSpeed = 10;
|
||||
|
||||
// Awake is always called before Start. Often used to initialize variables
|
||||
void Awake()
|
||||
{
|
||||
playerControls = new PlayerControlsMap();
|
||||
rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
// Often used to initialize variables which are dependent to other scripts/components
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
playerControls.Enable();
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
playerControls.Disable();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
// Update player direction. Very basic.
|
||||
Vector2 lookInput = playerControls.Player.Look.ReadValue<Vector2>();
|
||||
lookInput *= sensitivity * Time.deltaTime;
|
||||
Quaternion currentRotation = transform.rotation;
|
||||
currentRotation *= Quaternion.AngleAxis(lookInput.x, Vector3.up);
|
||||
transform.rotation = currentRotation;
|
||||
// We ignore vertical rotation as it would have no impact on the game
|
||||
|
||||
// Update player acceleration, using a force
|
||||
Vector2 mvtInput = playerControls.Player.Move.ReadValue<Vector2>();
|
||||
mvtInput *= speed * Time.deltaTime;
|
||||
rb.AddForce(currentRotation * new Vector3(mvtInput.x, 0, mvtInput.y), ForceMode.VelocityChange);
|
||||
|
||||
// Limit max speed. Warning: both maxSpeed and rigidbody linear damping affect max speed
|
||||
if (rb.linearVelocity.magnitude > maxSpeed) {
|
||||
rb.linearVelocity = rb.linearVelocity.normalized * maxSpeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Control/PlayerController.cs.meta
Normal file
2
Assets/Scripts/Control/PlayerController.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 477e133ae7cec0f44b29e6fb665c5e00
|
||||
1848
Assets/Scripts/Control/PlayerControlsMap.cs
Normal file
1848
Assets/Scripts/Control/PlayerControlsMap.cs
Normal file
File diff suppressed because it is too large
Load Diff
2
Assets/Scripts/Control/PlayerControlsMap.cs.meta
Normal file
2
Assets/Scripts/Control/PlayerControlsMap.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0540f779c45ae6e499f62ce2f8837a9b
|
||||
1068
Assets/Scripts/Control/PlayerControlsMap.inputactions
Normal file
1068
Assets/Scripts/Control/PlayerControlsMap.inputactions
Normal file
File diff suppressed because it is too large
Load Diff
14
Assets/Scripts/Control/PlayerControlsMap.inputactions.meta
Normal file
14
Assets/Scripts/Control/PlayerControlsMap.inputactions.meta
Normal file
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 052faaac586de48259a63d0c4782560b
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
|
||||
generateWrapperCode: 1
|
||||
wrapperCodePath:
|
||||
wrapperClassName:
|
||||
wrapperCodeNamespace:
|
||||
Reference in New Issue
Block a user