Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Help Im very new and I can't fix this still

Discussion in 'Scripting' started by Seechee, Sep 25, 2020.

  1. Seechee

    Seechee

    Joined:
    Sep 25, 2020
    Posts:
    8
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.Collections.Specialized;
    4. using System.Security.Cryptography;
    5. using System.Threading;
    6. using UnityEngine;
    7.  
    8. public class SwingingArm : MonoBehaviour
    9. {
    10.     //GameObjects
    11.     public GameObject LeftHand;
    12.     public GameObject RightHand;
    13.     public GameObject CenterEyeCamera;
    14.     public GameObject ForwardDirection;
    15.  
    16.     //Vector3 positions
    17.     private Vector3 PositionsPreviousFrameLeftHand;
    18.     private Vector3 PositionPreviousFrameRightHand;
    19.     private Vector3 PlayerPositionThisFrame;
    20.     private Vector3 PlayerPositionPreviousFrame;
    21.     private Vector3 PositionThisFrameLeftHand;
    22.     private Vector3 PositionThisFrameRightHand;
    23.  
    24.     //Speed
    25.     public float Speed = 70;
    26.     private float HandSpeed;
    27.  
    28.     // Start is called before the first frame update
    29.     void Start()
    30.     {
    31.         //Set original Previous frame positions at start up
    32.         PlayerPositionPreviousFrame = transform.position;
    33.         PositionPreviousFrameLeftHand = LeftHand.transform.position;
    34.         PositionPreviousFrameRightHand = RightHand.transform.position;
    35.     }
    36.  
    37.     // Update is called once per frame
    38.     void Update()
    39.     {
    40.         //Get the forward direction from the center eye camera and set it to the forward direction object
    41.         float yRotation = CenterEyeCamera.transform.eulerAngles.y;
    42.         ForwardDirection.transform.eulerAngles = new Vector3(0, yRotation, 0);
    43.  
    44.         //Get current positions of hands
    45.         PositionThisFrameLeftHand = LeftHand.transform.position;
    46.         PositionThisFrameRightHand = RightHand.transform.position;
    47.         //position off Player
    48.         PlayerPositionThisFrame = transform.position;
    49.  
    50.         //Get distance the hands and player has moved since last frame
    51.         var playerDistanceMoved = Vector3.Distance(PlayerPositionThisFrame, PlayerPositionPreviousFrame);
    52.         var leftHandDistanceMoved = Vector3.Distance(PositionsPreviousFrameLeftHand, PositionThisFrameLeftHand);
    53.         var rightHandDistanceMoved = Vector3.distance(PositionPreviousFrameRightHand, PositionThisFrameRightHand);
    54.  
    55.         //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
    56.         HandSpeed - ((leftHandDistanceMoved - playerDistanceMoved) + (rightHandDistanceMoved - playerDistanceMoved));
    57.  
    58.  
    59.         if (Time.timeSinceLevelLoad > 1f)
    60.             transform.position + = ForwardDirection.transform.forward * Speed * Time.deltaTime;
    61.  
    62.  
    63.  
    64.         //Set previous positions of hands for the next frame
    65.         PositionsPreviousFrameLeftHand = PositionThisFrameLeftHand;
    66.         PositionPreviousFrameRightHand = PositionThisFrameRightHand;
    67.         //Set player position previous frame
    68.         PlayerPositionPreviousFrame - PlayerPositionThisFrame;
    69.  
    70.  
    71.     }
    72. }
    73.  
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    eses likes this.
  3. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Going to be hard to help you without describing what the problem is.
     
    cyclSunity likes this.
  4. cyclSunity

    cyclSunity

    Joined:
    Jun 10, 2020
    Posts:
    123
    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.
     
  5. Seechee

    Seechee

    Joined:
    Sep 25, 2020
    Posts:
    8
    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 '='
     
  6. Oskar_Kasprzak

    Oskar_Kasprzak

    Joined:
    Mar 26, 2016
    Posts:
    61
    At line 60 you have "+ =" which is invalid. Just delete space between symbols so it is "+="
     
    cyclSunity likes this.
  7. Seechee

    Seechee

    Joined:
    Sep 25, 2020
    Posts:
    8
    thanks it works now!
     
    cyclSunity likes this.
  8. cyclSunity

    cyclSunity

    Joined:
    Jun 10, 2020
    Posts:
    123
    Wow, if ur really new I'm surprised you can script in Unity better than me