Looking for C# Code for ship shooter movement with the following properties.
Can move in all directions (X/Y) (Left/right is torque). No up/down movement. Just forward back.
Can turn in a complete circle if you hold down turn left/right key long enough
W for forward / Increase speed
S For backward / reduce speed
A/D for Left/right turning.
(been through a lot of various codes that do not fill these needs. most movement is left and right).
Hi there, there isnât probably any exact cutânâpaste code available, but it seems like you need asteroids kind of controls?
Most of the things you need is in Input class and Rigidbody class.
Check the input from player, if player presses L/R keys you define, he is turning.
If he presses W or up, he wants to use engines to create thrust.
Use AddForce (or other similar command from Rigidbody) along your ship transform.forward when accelerating. This way thrust will push ship to direction your ship nose is pointing.
Add rotation to RigidBody of ship using AddTorque or AddRelativeTorque. Depending on direction L/R make it negative.
I still cannot find a solution to this problem. I have spent 8 hours on this one task. Every time i get close the unity engine is not picking up the values for torque, etc.
Can someone please write this code for me in 5.5 Version of unity.
Iv tried 11-12 peoples version of how this should work. Not one of them works correctly. There seems to be outdated changes in the engine. Additionally, not even the website tutorial is working correctly with this.
First of all, copying code written by others isnât a solution, because the code you mentioned earlier does indeed work, the guy just didnât post the whole thing
Then Using code tags properly - Unity Engine - Unity Discussions
And finally watch some unity tutorials, they will get you started, and you will be able to write your owjn code
To use physics do Rigidbody AddForce and AddTorque instead of using transform.
The engine doesnât become âoutdatedâ to the point where movement and rotation stops working, so let go of that idea.
Movement and rotation are some of the most basic and fundamental concepts in Unity. There are an endless number of tutorials out there for it, and none of them are outdated. Just because a tutorial doesnât have âasteroidsâ or âspace shooterâ in the title, doesnât mean it wonât show you what you need to know.
In your code that you pasted, youâre using the deprecated keyword ârigidbodyâ. You canât use that keyword anymore, instead you must use âGetComponent()â like all other components besides âtransformâ. The error you get from using ârigidbodyâ tells you exactly that.