Char Playermoviment Script Problem in Unity 5

Asked

Viewed 198 times

1

Char Playermoviment Script Problem in Unity 5 Alleged problem on line 70 in "Quaternion" inserir a descrição da imagem aqui

using UnityEngine;
using System.Collections;

public class PlayerMoviment : MonoBehaviour 
{
	//velocidade do Mago
	public float speed = 6f;

	//Vetor responsavel pelo movimento do Mago
	Vector3 movement;

	//Responsavel pela transiçao da animaçao
	Animator anim;

	//Responsavel pela fisica do objeto
	Rigidbody playerRigidbody;

	//Mascara de chao
	int floorMask;

	//Informaçoes para magia
	float camRayLenght = 100f;

	void Awake()
	{	//Atribuir mascara de camada
		floorMask = LayerMask.GetMask ("Floor"); 

		//Atribuir as referencias
		anim = GetComponent <Animator> ();
		playerRigidbody = GetComponent <Rigidbody> ();

	}



	void FixedUpdate()
	{
		float h = Input.GetAxisRaw ("Horizontal");
		float v = Input.GetAxisRaw ("Vertical");

		Move (h, v);
		Turning ();
		Animating (h, v);
	}



	//movimento do Mago
	void Move (float h, float v)
	{	//Determina o movimento
		movement.Set (h, 0f, v);
		//normaliza o movimento
		movement = movement.normalized * speed * Time.deltaTime;
		//Efetua o movimento do Mago
		playerRigidbody.MovePosition (transform.position + movement);

	}
	//Movimento Giratorio do Mago
	void Turning ()
	{
		Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);

		RaycastHit floorHit;

		if (Physics.Raycast (camRay, out floorHit, camRayLenght, floorMask)) 
		{
			Vector3 playerToMouse = floorHit.point - transform.position;
			playerToMouse.y = 0f;

			Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
			playerRigidbody.MovePosition(newRotation);
		
		}		


	}

	void Animating(float h, float v)
	{
		bool walking = h != 0f || v != 0f;

		anim.SetBool ("IsWalking", walking);	
	}

}

inserir a descrição da imagem aqui

  • 2

    Post the code not an image of it so it’s easier for other members to test

  • 2

    what error? Try to post the error to facilitate @Cmdsapessoa analysis

1 answer

3


The cause of the error is simple and direct: the method MovePosition wait as parameter one Vector3 and not a Quaternion. How are you passing one Quaternion as a parameter on the line...

playerRigidbody.MovePosition(newRotation);

...the tool generates the error to indicate the invalid parameter.

The question then is, what did you want to do? If you wanted to guide the transformation (make the object "stay turned"/"look" towards the mouse direction), just do as in the example of documentation, and exchange this line for:

transform.rotation = newRotation;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.