- Home /
Movement FPS Independent, how to?
Hello people, I've already asked this here a few times, but no one awsered, so let's try again. I've made a Character controller myself, and I tought i did things right when it comes to FPS independency, but when I tessted in other machines, it does'nt seem so.
My code is pretty big. but the main lines are these:
if(grounded == false) //Gravity for falling
{finalmovement.y -= gravity * Time.deltaTime;}
if(Input.GetButtonDown("Jump")) //Jumping
{finalmovement.y = 7;}
myTransform.position += (myTransform.rotation * finalmovement)*Time.deltaTime; //Overall movement
I tought it is ok, if my character is not on the ground, the gravity is applied with Time.deltaTime, and if I jump, the Y of finalmovement goes to 7 and then starts to go down with the gravity to make my character move downward.
But the problem is, when i have low fps, my character doesn't jump as high. why? It seems that the gravity is being applied more strongly ( I guess its because the Time between frames is bigger ), in other words, my movement is not FPS independent, even if I use Time.deltaTime. How can I solve this? Is my guess about the problem right? Thanks in advance.
Answer by sparkzbarca · Dec 27, 2013 at 02:01 AM
myTransform.position += (myTransform.rotation * finalmovement)
ok well this line above, i can't believe the compiler is even allowing such a thing
you have
vector3 += quanternion vector3 float
now vectors can be rationally multipled against floats (and probably quans too) but multiplying a vector3 against a quan is just wierd. a quan is 4 values a vector is 3 i've no idea how you logically compute that.
Irregardless remove the mytransform.rotation. There is no reason it should ever be in there that is causing wierd bugs and is probably your problem.
Also you probably should use fixed update for charactermovement not update. The thing is fixedupdate is where physics occurs, if you want to use colliders and things you want to use fixedupdate. That's just a suggestion though, my guess is removing the rotation will fix it.
Well, you should read more about multiplying quads and vector 3... It's possible, and sorry, but it have nothing to do with my problem... Also, i'm not using unity physics for anything in my game, only for raycasting, i've made my own gravity and I detect if its grounded via raycast. Should I use FixedUpdate anyway?
Thanks for your awser.
can you explain why your rotation is modifying your position. I mean Unity stores those two as completely seperate variables for a reason. your basically saying I want the way im facing to decide where i am in space.
Your saying if i face forward i want to stand here but if i face left for example dont just rotate me in place but physically move my bodies position as well.
to answer your question, I think you should use fixedupdate or even possibly a coroutine at half fixedupdate. The thing is you probably dont need to actually be checking anything more than 30 times a second unless your are just going crazy fast.
But if you have a link or soemthing to where you got the idea to use rotation in your position, this just seems like a terrible idea. I can't imagine how the point in space that the center of your object should be located at would ever be affected by its rotation.
if you dont $$anonymous$$d me asking, does it work as you expect if you remove the rotation line?
Actually, the quad doesnt modify the position by itself. It deter$$anonymous$$es wich direction the Vector3 it is multiplying is facing. I use this, so, when i want to make my character move forward, i add a number to finalmovement.z, and multiply it by the rotation of my character, so, finalmovement.z will became the direction my character is facing, you get it?
Also, I've tried putting these lines in Fixed Update, but it looked really bad, my character seems to be shaking, and the movement became very rigid.
Your answer
Follow this Question
Related Questions
Jumping increases movement speed 1 Answer
Why does this script make my camera jump when I move back? 1 Answer
How do I create WASD controls for a fps? 3 Answers
What is the best way to move a character for an FPS? 1 Answer
How can I get a responsive rigidbody FPS controller without acceleration that reacts to forces? 2 Answers