using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Security.Cryptography;
using System.Threading;
using UnityEngine;
public class SwingingArm : MonoBehaviour
{
//GameObjects
public GameObject LeftHand;
public GameObject RightHand;
public GameObject CenterEyeCamera;
public GameObject ForwardDirection;
//Vector3 positions
private Vector3 PositionsPreviousFrameLeftHand;
private Vector3 PositionPreviousFrameRightHand;
private Vector3 PlayerPositionThisFrame;
private Vector3 PlayerPositionPreviousFrame;
private Vector3 PositionThisFrameLeftHand;
private Vector3 PositionThisFrameRightHand;
//Speed
public float Speed = 70;
private float HandSpeed;
// Start is called before the first frame update
void Start()
{
//Set original Previous frame positions at start up
PlayerPositionPreviousFrame = transform.position;
PositionPreviousFrameLeftHand = LeftHand.transform.position;
PositionPreviousFrameRightHand = RightHand.transform.position;
}
// Update is called once per frame
void Update()
{
//Get the forward direction from the center eye camera and set it to the forward direction object
float yRotation = CenterEyeCamera.transform.eulerAngles.y;
ForwardDirection.transform.eulerAngles = new Vector3(0, yRotation, 0);
//Get current positions of hands
PositionThisFrameLeftHand = LeftHand.transform.position;
PositionThisFrameRightHand = RightHand.transform.position;
//position off Player
PlayerPositionThisFrame = transform.position;
//Get distance the hands and player has moved since last frame
var playerDistanceMoved = Vector3.Distance(PlayerPositionThisFrame, PlayerPositionPreviousFrame);
var leftHandDistanceMoved = Vector3.Distance(PositionsPreviousFrameLeftHand, PositionThisFrameLeftHand);
var rightHandDistanceMoved = Vector3.distance(PositionPreviousFrameRightHand, PositionThisFrameRightHand);
//Add them up to get the handspeed from the user minus the movement of the player to neglect the movement of the player from The equation
HandSpeed - ((leftHandDistanceMoved - playerDistanceMoved) + (rightHandDistanceMoved - playerDistanceMoved));
if (Time.timeSinceLevelLoad > 1f)
transform.position + = ForwardDirection.transform.forward * Speed * Time.deltaTime;
//Set previous positions of hands for the next frame
PositionsPreviousFrameLeftHand = PositionThisFrameLeftHand;
PositionPreviousFrameRightHand = PositionThisFrameRightHand;
//Set player position previous frame
PlayerPositionPreviousFrame - PlayerPositionThisFrame;
}
}
How to report problems productively in the Unity3D forums:
Help us to help you.
ALSO: DO NOT DUPLICATE-POST! You already posted this same question here: I am new and don't know how to fix this code
1 Like
Going to be hard to help you without describing what the problem is.
1 Like
Lol yeah, he is right though, explain what this is. I saw that the script is called “SwingingArm.cs”, but that’s all I know.
sorry I posted them but they arent showing up and had to go to the hospital, the error codes are Assets\SwingingArm.cs(60,34): error CS1525: Invalid expression term ‘=’
At line 60 you have “+ =” which is invalid. Just delete space between symbols so it is “+=”
1 Like
thanks it works now!
1 Like
Wow, if ur really new I’m surprised you can script in Unity better than me