C
C
candy3032021-07-19 13:57:19
Unity
candy303, 2021-07-19 13:57:19

How to fix such an error with a jump?

Hello, please help me with this error. Can't find a solution

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    private Rigidbody rb;

    void Start()
    {
    	rb = GetComponent<Rigidbody>();
    }

    void Update()
    {
    	if (Physics.Raycast(transform.position, Vector3.down, GetComponent<BoxCollider>().size.y / 2 + 0.4f))
    	{
    		Quaternion rot = transform.rotation;
    		rot.z = Mathf.Round(rot.z / 90) * 90;
    		transform.position = rot;
    		if (Input.GetMouseButtonDown(0)) {
    			rb.velocity = Vector3.zero;
    			rb.AddForce(Vector2.up * 55000);
    		}
    	}
    	else {
    		transform.Rotate(Vector3.back * 5f);
    	}
    }
}


Error: Cannot implicitly convert type 'UnityEngine.Quaternion' to 'UnityEngine.Vector3'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-07-19
@candy303

It seems that you wanted to write

Quaternion rot = transform.rotation;
rot.z = Mathf.Round(rot.z / 90) * 90;
transform.position = rot; // Взяли квартернион из rotation, и пытаемся изменить position...

BUT
Quaternion rot = transform.rotation;
rot.z = Mathf.Round(rot.z / 90) * 90;
transform.rotation = rot;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question