I am creating a horizontal side-scrolling shooter which I plan to release on mobile devices. How can I set up the ship so that:
- It can be moved up/down/left/right freely (with varying horizontal/vertical speeds)
- Collide and stop against obstacles (i.e. IF collision with obstacle STOP)
- Diagonal movement against horizontal plane (down + right input) should move right pressed against floor
The ship must not be able to pass through obstacles.
I created a custom character controller which simply adjust position based on velocity. I cannot figure out how to detect collision and avoid moving through obstacles. There must be an easier way to achieve this simple requirement.
Note: To clarify, the camera follows the ship, it does not automatically scroll. The player can stop the ship by releasing input button.
I was storing my own
velocityvector which I was then applying usingtransform.Translate. This obviously was ignoring any collision detection and would have required a custom collision detection implementation.Instead I found that the
Rigidbodycomponent contains its ownvelocityvariable. That velocity value can be easily altered and the object will automatically translate and collide with obstacles. Here is an example:This appears to work quite well. Comments would be appreciated 🙂