- Home /
Question by
Sayden96 · Feb 26 at 06:21 PM ·
rotationscripting problemerrortransform.position
Transform Position doesn't work
I have an script when the player touch the collider, the arm rotates and after return to the original form but doesn't work and the arm return in a wrong position. Any ideas to solvent this problem?
The Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArmParentScript : MonoBehaviour
{
public float speedRotate;
public float StartSpeedRotate;
public GameObject Arm;
public bool isCounting = false;
public bool isRouting = false;
public GameObject pivotObject;
private PlayerMovement player;
//Vector3 nextPos;
//public Transform startPos;
private Vector3 snapPosition;
// Start is called before the first frame update
void Start()
{
player = GameObject.Find("PlayerV2").GetComponent<PlayerMovement>();
//nextPos = startPos.position;
snapPosition = this.transform.position;
}
// Update is called once per frame
void Update()
{
if (isCounting)
{
StartCoroutine("WaitToStartR");
}
if (isRouting)
{
speedRotate = StartSpeedRotate;
//Arm.transform.Rotate(Vector3.forward * speedRotate * Time.deltaTime);
//Arm.transform.RotateAround(pivot.position, Vector3.forward, speedRotate * Time.deltaTime);
Arm.transform.RotateAround(pivotObject.transform.position, Vector3.forward, speedRotate * Time.deltaTime);
StartCoroutine("WaitToStopR");
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
isCounting = true;
collision.transform.SetParent(transform);
}
}
private void OnCollisionExit2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
isCounting = false;
collision.transform.SetParent(null);
player.transform.eulerAngles = new Vector3(0, 0, 0);
}
}
IEnumerator WaitToStartR()
{
yield return new WaitForSeconds(5f);
isRouting = true;
isCounting = false;
}
IEnumerator WaitToStopR()
{
yield return new WaitForSeconds(3f);
isRouting = false;
speedRotate = 0;
Arm.transform.rotation = Quaternion.identity;
Arm.transform.position = snapPosition;
}
}
Image to error:
error.png
(322.2 kB)
Comment
Your answer
Follow this Question
Related Questions
What is wrong with my script? 1 Answer
FPS Controller rotation,FPS Controller rotation problem 0 Answers
Can anyone provide some help with that error ? 1 Answer
Rotation drift with transform.eulerAngles 0 Answers
UCE0001 and BCE0044 Errors 1 Answer