Posted April 17, 2021 by Brodie Farrell-Oates
#movement
The player is controlled by the Eight Way Movement script - with additions added to include sprinting in short bursts (set to 0.5 seconds currently). There is a trail renderer on the player to give a sense of motion, the colours and visual style of this will be refined.
Next step was to add a mark to the player sprite so that the player has an indication as to which way they are facing. I simply added a small black rectangle to the player sprite.
I then added a new script so that the player would rotate to face the mouse, which would not affect their movement direction. I found a really handy 'bite-sized' tutorial to achieve this at: www.youtube.com/embed/Geb_PnF1wOk
var dir = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position); var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
(Indie Nuggets, 2018)
Now we have fast and fluid movement, with independent aiming towards the mouse.
Next steps:
Indie Nuggets, 2018. Unity Nuggets: How to "Look At" Mouse in 2D Game. [video]