简体   繁体   中英

Unity player input system

I have just created a roll-a-ball game in unity using the Unity player input package. Is this recommended for all player assets instead of using the normal "transform.Translate" for moving the player:

transform.Translate(Vector3.forward * speed * horizontalInput);

Also, does the player input system work on none spherical shapes to move them, since I'm using a sphere in the roll-a-ball game that appears to use it's rigidBody component and the physics engine?

I would like to know so I can use the best system for my next project.

I think you are confusing concepts.

Input system is responsible only for, well, input. You still have to decide how to interprete the values you are getting from it, irrespective of method of reveicing input.

Moving player is another story. You can use physics to move objects, or simply change their position either by changing their transform.position or using mentioned transform.Translate(params) .

As far as the input goes, you can hard-code reading it yourself, or you can use old or new unity system, probably using the last one is the best idea.

Regarding movement, use physics if you want collisions and/or more realistic movement. For other stuff, go with changing transform yourself. The difference between transform.Translate(vector) and transform.position += vector is that Translate takes into account object's current rotation and scale. Sometimes it's desirable, sometimes it just complicate things and you use the latter method.

If you use Translate on objects other than sphere, it will work fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM