I am trying to make parallax scrolling effect with tutorial, but it doesn’t work because of adding wrong types of operands. Any help? Here’s the code.
void Update()
{
deltaCameraPosition = cameraTransform.position - previousCameraPosition;
Vector3 parallaxPosition = new Vector3(transform.position.x
+ (deltaCameraPosition * parallaxFactor), transform.position.y, transform.position.z);
transform.position = parallaxPosition;
previousCameraPosition = cameraTransform.position;
}
transform.position
is Vector3;
transform.position.x
is float;
I assume that deltaCameraPosition is Vector3 and parallaxFactor is float.
(deltaCameraPosition * parallaxFactor)
is Vector3;
transform.position.x + (deltaCameraPosition * parallaxFactor)
is adding float and Vector3 and that’s an undefined operation because it doesn’t make much sense. I can only guess what you are trying to achieve, but perhaps it could be
Vector3 parallaxPosition = transform.position + (deltaCameraPosition * parallaxFactor);
?
1 Like