Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [SOLVED] how can i move my character always in the mouse angle ?

Author
Message
SkinK4ir3
9
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 11th Jan 2022 15:09
Hello everyone, I would like to always move my character in the angle that the mouse is, if I press the W key, it moves forward in the mouse angle, if S, it moves backward in the mouse angle and etc. Does anyone know how I do this in a simple and effective way?

my code is looking like this >

The author of this post has marked a post as an answer.

Go to answer

Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 11th Jan 2022 16:04 Edited at: 11th Jan 2022 16:26
This post has been marked by the post author as the answer.
This is one of those situations where you are reminded of the times you were at school and asked your maths teacher when you would ever use sine and cosine in the real world.
This is that time


I don't know what your sprite looks like but this code assumes it is facing up. If it isn't then you'll need to swap around the additional amounts on the angles (or redraw your sprite = easier)
SkinK4ir3
9
Years of Service
User Offline
Joined: 25th Aug 2015
Location:
Posted: 11th Jan 2022 18:51
Awesome Scraggle
thanks u very much !! solve my problem!

Login to post a reply

Server time is: 2024-11-23 08:14:48
Your offset time is: 2024-11-23 08:14:48