The question is answered, right answer was accepted
Error CS0019: Operator * cannot be applied to operands of types 'UnityEngine.Vector3' and 'UnityEngine.Vector3'
Here is the important part of code, it's inside a FixedUpdate if that matters:
float moveHorizontal = joystick.Horizontal ();
float moveVertical = joystick.Vertical ();
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
//Rotate direction vector with the camera
Vector3 rotatedDir = camTransform.TransformDirection(movement);
rotatedDir = new Vector3 (rotatedDir.x, 0, rotatedDir.z);
rotatedDir = rotatedDir.normalized * movement;
rb.AddForce (rotatedDir * velocity);
The problem is in the line ''rotatedDir = rotatedDir.normalized * movement;''
'+' and '-' do work but '*' (which is what I need) and '/' don't. That part of my code is to rotate the direction of the vector with the camera(as said in the comment). Anyone know what I'm doing wrong? And why does it speficy the same operand twice in the error?
Answer by unity_bcUiA2t7GqTPBA · Sep 29, 2017 at 10:51 AM
nevermind go it.
rotatedDir = rotatedDir.normalized * movement;
should be
rotatedDir = rotatedDir.normalized * movement.magnitude;
Dunno why but it works
Follow this Question
Related Questions
A Problem With A Script Of GUI.HorizontalSlider It Do not Move? 0 Answers
I have a problem with this script and an error appeared, does anyone know why? 0 Answers
How to reference this game object to another class 0 Answers
Can someone tell me what is wrong with this script? 1 Answer
Im having a problem with my C# code 1 Answer