Noob question for a 2.5d platformer -
Should I use transform.translate for left and right movement, and a physics 'addforce' for upward thrust of jump ?
Currently I calculate a 'moveDirection' using Input.GetAxis("Horizontal") and I add a 'moveDirection.y = jumpHeight;' when jump key is pressed, and then finally apply it all with
controller.Move(moveDirection * Time.deltaTime);
I can upload my entire code if necessary but I think you'll get the idea. It just seems that there are so many ways to move things and I'm having trouble figuring out what's best.
P.S. is it possible to do a comparison on a translate position and a float like this:
if (gameObject.transform.position.y <= jumpMaxFloatVar)
it doesn't seem to work, I can print out gameObject.transform.position.y but my guess is it's not a float ?
As I have said before in several answers, the translation concept is often confused for movement. This is a common misconception as movement is the continous flow between two points, the transform property can manipulate time and space and go to places by changing the x,y,z variables. If done over time it looks like movement , but actually the engine will not see this as movement and thus ignore events such as collisions.
You avoid this problem by using a character controller object attached to your "player" object and manipulate that with it's move function which will , as the name implies, move the character, rather then teleport it a lot in very little time.
Physics can be used to literally kick and push something around, but imagine in real life what that would be like? Jumping by applying a kick at the right moment? Sure, easy, and now navigate a maze? Would that be harder? What about slopy mountains with ice patches and wind blowing around? It's going to get really hard really fast making it a not so worthwhile time investment to apply physics to jump in my experience.
So the conclusion I will make for your suggested approach:
Should I use transform.translate for
left and right movement, and a physics
'addforce' for upward thrust of jump ?
I would say, No, use character controller options instead and keep in mind that if you change gravity in the game or in the future of the game, you need to have considered that in the design. So jumping with +9.81 all the time could be a problem later if you want to build a low-grav mode such as in the Unreal Tournament Environment.
SideNote: All these answers are actually quite easy to extrapolate from the great naming conventions the unity3D group has given their objects and properties. They don't just call a PLUS a MINUS (which some pesky students may overload to spice up your monday). Character Controller really means, it controls the character. These names should be a big marker for everyone to consider using it for that goal , and avoid sidetracking untill ABSOLUTELY NECESSARY!