Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Course Moodle link: https://moodle.taltech.ee/course/view.php?id=30786
- //
- // Package with robot model: https://moodle.taltech.ee/mod/resource/view.php?id=267745
- // Package with project from the first week: https://moodle.taltech.ee/mod/resource/view.php?id=359501
- // Package with Vuforia AR markers: https://moodle.taltech.ee/mod/resource/view.php?id=361128
- // AR image target file: https://moodle.taltech.ee/mod/resource/view.php?id=361150
- //
- // Vuforia developer portal: https://developer.vuforia.com/
- // Vuforia developer license key
- AVzplhT/////AAABmWMwu8cGuUwhkPCvIfxSgcg9rFoJMxCW8fyW6A55qN089iVX/aB3Pyc1lcCddj8aTfM4Vpq4rEZvbq9ClNOPps7DjN84Bq222WnMfP0e7I2Pp7vsJdGVxc9Rvi6lPIecGIt/weckG1r0Et+puXd5xvS2Zrgaoycp8CYskinJZzrSa3IesCGh3SRbW0xJIMcxJs7Zb4/+vGBlR/rbB62I1DlALeKpglQGnY5YqPsSzqCqatQ/JhUPHXXSAs3AB19gOBtjtzhdt0KmSBSmE+FmO0JoE1DXp2IRFqjCG9HPRQKvUju3qMX0PuHwVVR/ccE/gkSzGzcD5wKRLCCoNebkhSXMVxRhguGi5RF1yZ7vTLhc
- // RobotController script
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class RobotController : MonoBehaviour
- {
- [System.Serializable]
- public class RobotJoint
- {
- public Transform joint;
- public float speed = 60f;
- public float minAngle = -90f;
- public float maxAngle = 90f;
- public float currentAngle = 0f;
- }
- public float speed = 45f;
- public List<RobotJoint> robotJoints = new List<RobotJoint>();
- public int selectedJointIndex = 0;
- private bool isUiIncreasingJointAngle = false;
- private bool isUiDecreasingJointAngle = false;
- private RobotJoint SelectedRobotJoint => robotJoints[selectedJointIndex];
- // Update is called once per frame
- void Update()
- {
- float angleDelta = 0;
- // Apply inputs
- angleDelta = ProcessKeyInputs(angleDelta);
- angleDelta = ProcessUiInputs(angleDelta);
- // Apply limits
- angleDelta = ApplyJointLimits(angleDelta);
- SelectedRobotJoint.currentAngle += angleDelta;
- Vector3 rotation = new Vector3(0f, 0f, angleDelta);
- SelectedRobotJoint.joint.Rotate(rotation);
- }
- private float ProcessKeyInputs(float angleDelta)
- {
- bool leftPressed = Input.GetKey(KeyCode.LeftArrow);
- if (leftPressed)
- {
- angleDelta += speed * Time.deltaTime;
- }
- bool rightPressed = Input.GetKey(KeyCode.RightArrow);
- if (rightPressed)
- {
- angleDelta -= speed * Time.deltaTime;
- }
- bool spacePressed = Input.GetKeyDown(KeyCode.Space);
- if (spacePressed)
- {
- SelectNextJoint();
- }
- return angleDelta;
- }
- private float ProcessUiInputs(float angleDelta)
- {
- if (isUiIncreasingJointAngle)
- {
- angleDelta += speed * Time.deltaTime;
- }
- if (isUiDecreasingJointAngle)
- {
- angleDelta -= speed * Time.deltaTime;
- }
- return angleDelta;
- }
- private float ApplyJointLimits(float angleDelta)
- {
- float expectedAngle = SelectedRobotJoint.currentAngle + angleDelta;
- if (expectedAngle < SelectedRobotJoint.minAngle)
- {
- angleDelta = SelectedRobotJoint.minAngle - SelectedRobotJoint.currentAngle;
- }
- if (expectedAngle > SelectedRobotJoint.maxAngle)
- {
- angleDelta = SelectedRobotJoint.maxAngle - SelectedRobotJoint.currentAngle;
- }
- return angleDelta;
- }
- public void StartIncreasingJointAngle()
- {
- isUiIncreasingJointAngle = true;
- isUiDecreasingJointAngle = false;
- }
- public void StartDecreasingJointAngle()
- {
- isUiIncreasingJointAngle = false;
- isUiDecreasingJointAngle = true;
- }
- public void StopRobotMovement()
- {
- isUiIncreasingJointAngle = false;
- isUiDecreasingJointAngle = false;
- }
- public void SelectNextJoint()
- {
- selectedJointIndex += 1;
- if (selectedJointIndex >= robotJoints.Count)
- {
- selectedJointIndex = 0;
- }
- }
- }
- // Updated contents of packages.json
- {
- "scopedRegistries": [
- {
- "name": "npmjs",
- "url": "https://registry.npmjs.org/",
- "scopes": [
- "io.extendreality"
- ]
- }
- ],
- "dependencies": {
- "io.extendreality.tilia.camerarigs.spatialsimulator.unity": "1.2.31",
- "io.extendreality.tilia.camerarigs.trackedalias.unity": "1.5.7",
- "io.extendreality.zinnia.unity": "1.30.0",
- "com.unity.collab-proxy": "1.2.16",
- "com.unity.ide.rider": "1.1.4",
- "com.unity.ide.vscode": "1.2.3",
- "com.unity.test-framework": "1.1.20",
- "com.unity.textmeshpro": "2.1.1",
- "com.unity.timeline": "1.2.17",
- "com.unity.ugui": "1.0.0",
- "com.unity.modules.ai": "1.0.0",
- "com.unity.modules.androidjni": "1.0.0",
- "com.unity.modules.animation": "1.0.0",
- "com.unity.modules.assetbundle": "1.0.0",
- "com.unity.modules.audio": "1.0.0",
- "com.unity.modules.cloth": "1.0.0",
- "com.unity.modules.director": "1.0.0",
- "com.unity.modules.imageconversion": "1.0.0",
- "com.unity.modules.imgui": "1.0.0",
- "com.unity.modules.jsonserialize": "1.0.0",
- "com.unity.modules.particlesystem": "1.0.0",
- "com.unity.modules.physics": "1.0.0",
- "com.unity.modules.physics2d": "1.0.0",
- "com.unity.modules.screencapture": "1.0.0",
- "com.unity.modules.terrain": "1.0.0",
- "com.unity.modules.terrainphysics": "1.0.0",
- "com.unity.modules.tilemap": "1.0.0",
- "com.unity.modules.ui": "1.0.0",
- "com.unity.modules.uielements": "1.0.0",
- "com.unity.modules.umbra": "1.0.0",
- "com.unity.modules.unityanalytics": "1.0.0",
- "com.unity.modules.unitywebrequest": "1.0.0",
- "com.unity.modules.unitywebrequestassetbundle": "1.0.0",
- "com.unity.modules.unitywebrequestaudio": "1.0.0",
- "com.unity.modules.unitywebrequesttexture": "1.0.0",
- "com.unity.modules.unitywebrequestwww": "1.0.0",
- "com.unity.modules.vehicles": "1.0.0",
- "com.unity.modules.video": "1.0.0",
- "com.unity.modules.vr": "1.0.0",
- "com.unity.modules.wind": "1.0.0",
- "com.unity.modules.xr": "1.0.0"
- }
- }
RAW Paste Data