Unity c# not recognizing Float as a Value Type, the script is identical to tutorial but the game still bugs out
I'm new to Unity so I'm starting small with a tutorial on how to make PONG. This is the tutorial I was using: https://www.youtube.com/watch?v=jEeT23Rc0P0
I've quadruple checked my code but it is identical to his in the video. The only difference I could find is that the Float value type is green in mine and blue in his. I figured out that when typing out "float" the auto fill box only lists it as a keyword while in the video it's marked as a value type. The same thing applies to the type "Int". I'm not sure if this is what is causing the game to bug out but it doesn't make sense that I've copied it exactly and I'm getting different results.
The bug is the same as his at the end of the video in that the paddle doesn't move smooth along the y axis with the up and down arrows but flickers back and forth from the top to the bottom. Even after I made the change that should have fixed it mine still had the bug.
This is the code I'm using and It's a component on the Paddle sprite:
using UnityEngine; using System.Collections; public class Paddle : MonoBehaviour {
public float paddleSpeed = 1F;
public Vector3 playerPos = new Vector3(0,0,0);
void Update ()
{
float yPos = gameObject.transform.position.y + (Input.GetAxis("Vertical") * paddleSpeed);
playerPos = new Vector3 (-20,Mathf.Clamp(yPos, 11,-11),0);
gameObject.transform.position = playerPos;
}
}
Not sure what to do about this, trying to learn C# so I can make a game I've been wanting to make for a while now. This is just a frustrating road block that I hope someone can help me fix it.
Any help is greatly appreciated.
i would use lerp for movement like this
Answer by Fulacine · Jan 19, 2016 at 08:36 AM
the Negative is on the wrong 11 put the negative on the first 11 playerPos = new Vector3 (-20,Mathf.Clamp(yPos, -11,11),0);
I check out the video and tried your code out and this was the problem. @ MattDollar
sadly this wont make a difference, you have already told the complier that this is a floating point value with the 'f', what could work though is making that value smaller say 0.1f
Answer by MattDollar · Jan 19, 2016 at 02:43 PM
It's working now but I don't know why.
I know for a fact I made that change and I thought that's the code I put in the question. Not sure what the deal is but I'm glad it's working now. maybe I just didn't save it properly when I fixed it. Oh well. Thanks for the help.
Your answer

Follow this Question
Related Questions
why doesnt change my money float? 2 Answers
Get Temperature Value and Prompt an Action 0 Answers
Can you do float + float 1 Answer
How to convert User Values into degree(Angle)?? 2 Answers
Is my MonoDeveloped Glitchd ??? 1 Answer