Discuss Scratch

TheSandwichViking
Scratcher
3 posts

I can't make my sprite face the direction he is moving.

I am creating a game for a computing class, and the game will involve a room full of npc sprites that wander around randomly, (they don't need to interact with anything). I can make them move around randomly, and I have given them simple walk cycles, but I can't manage to make them face the direction they are moving. I could make them face left, right up and down, but I really want them to be able to face 360 degrees, and change as they change direction.
awesome-llama
Scratcher
1000+ posts

I can't make my sprite face the direction he is moving.

There is an input with the dropdown, so you can set directions other than the dropdown choices of -90, 0, 90 and 180.
pointindirection12
I find your post hard to understand. I think you also want smooth rotation, instead of just instantly facing direction.
repeat10turn9degrees turns 90 degress clockwise.
TheSandwichViking
Scratcher
3 posts

I can't make my sprite face the direction he is moving.

That's not the problem sorry. I've made a sprite that moves around totally randomly, 360 degrees of choice, anywhere on screen. I want him to face the direction he is moving. I will not be controlling him, there is no input. I'm hopeless at this.
Candylanguagegirl
Scratcher
1000+ posts

I can't make my sprite face the direction he is moving.

Could you share the project? It's usually easier to work with coding when you can have it in the editor and can test it.
Also, this should go in the help with scripts forum. I'll report it to be moved for ya.
spyroclub1
Scratcher
18 posts

I can't make my sprite face the direction he is moving.

whenclickedifkeyleft arrowpressed?thenswitchcostumetoturn left

Hope this helps!
asivi
Scratcher
1000+ posts

I can't make my sprite face the direction he is moving.

whenclickedsetrotationstyleall aroundgotox:y:0pointindirectionpickrandom30to120showforevermove3stepsifonedge,bouncewhenclickedforeverwaitpickrandom3to10secsturnpickrandom-60to60degrees
dov3lyn
Scratcher
100+ posts

I can't make my sprite face the direction he is moving.

TheSandwichViking wrote:

I am creating a game for a computing class, and the game will involve a room full of npc sprites that wander around randomly, (they don't need to interact with anything). I can make them move around randomly, and I have given them simple walk cycles, but I can't manage to make them face the direction they are moving. I could make them face left, right up and down, but I really want them to be able to face 360 degrees, and change as they change direction.
Try
setrotationstyleleft-right
Then,
pointindirection90°
pointindirection-90°

Hope this helps!
Thelnvoker
Scratcher
100+ posts

I can't make my sprite face the direction he is moving.

Try using this block:

pointindirection

For right, do 90 degrees, left, -90 degrees, up, 0 degrees, and down, 180 degrees.

For instance:

when rightkeypressedpointindirection90move10steps

Hope this helps!
deck26
Scratcher
1000+ posts

I can't make my sprite face the direction he is moving.

Your explanation isn't totally clear but it sounds like a rotation style problem.

If it doesn't matter if the sprite is upside down, for example a top-down view) and it can turn in any direction just make sure the rotation style is set to all-round. Also make sure that the costume faces right in the costume editor - in the editor it should always be as you want it to appear when facing right (90 degrees).

If you want to avoid the problem of a sprite ending up upside down you have to do more work with separate costumes but it would be easier to help if we can see what you have.
asivi
Scratcher
1000+ posts

I can't make my sprite face the direction he is moving.

Perhaps you are moving with “glide_secs_to_x_y”, if this is your case create 2 variables for random coodinates 1 for x and the orher for y positions
setglideXtopickrandom-220to220 here your own range for coordinatessetglideYtopickrandom-160to160pointindirectiondirectionyou might to calculate "direction" with Pythagorean theorem.glide...secstox:glideXy:glideYyou might calculate a time to complete accordingly to the distance.

Last edited by asivi (Oct. 10, 2016 09:59:38)

mario
Scratcher
9 posts

I can't make my sprite face the direction he is moving.

dfklkvrd s
mario
Scratcher
9 posts

I can't make my sprite face the direction he is moving.

Thelnvoker wrote:

Try using this block:

pointindirection

For right, do 90 degrees, left, -90 degrees, up, 0 degrees, and down, 180 degrees.

For instance:

when rightkeypressedpointindirection90move10steps

Hope this helps!
deck26
Scratcher
1000+ posts

I can't make my sprite face the direction he is moving.

mario wrote:

Thelnvoker wrote:

Try using this block:

pointindirection

For right, do 90 degrees, left, -90 degrees, up, 0 degrees, and down, 180 degrees.

For instance:

when rightkeypressedpointindirection90move10steps

Hope this helps!
Please don't necropost.
logicil
Scratcher
54 posts

I can't make my sprite face the direction he is moving.

asivi wrote:

Perhaps you are moving with “glide_secs_to_x_y”, if this is your case create 2 variables for random coodinates 1 for x and the orher for y positions
setglideXtopickrandom-220to220 here your own range for coordinatessetglideYtopickrandom-160to160pointindirectiondirectionyou might to calculate "direction" with Pythagorean theorem.glide...secstox:glideXy:glideYyou might calculate a time to complete accordingly to the distance.
Idk if I did it right, but this method didn't work for me. Does it have to be squared?

Yes I know this is technically necroposting, but I'd rather not create a new thread.

Last edited by logicil (Nov. 5, 2019 00:39:39)

Trevisiol17
New Scratcher
2 posts

I can't make my sprite face the direction he is moving.

I’m trying to do this on iPad
soccersword5971
Scratcher
1 post

I can't make my sprite face the direction he is moving.

scratchPro86
New Scratcher
15 posts

I can't make my sprite face the direction he is moving.

But how do you do it with left and right arrows
I know that
set glideXtopickrandom-220to220set glideYtopickrandom-160to160pointindirectiondirectionglidesecstox:glideXy:glideY

But how do you do it with left and right arrow keys??
deck26
Scratcher
1000+ posts

I can't make my sprite face the direction he is moving.

scratchPro86 wrote:

But how do you do it with left and right arrows
I know that
set glideXtopickrandom-220to220set glideYtopickrandom-160to160pointindirectiondirectionglidesecstox:glideXy:glideY

But how do you do it with left and right arrow keys??
Please create your own topic rather than necroposting.

ifkeyright-arrowpressed?thenpointindirection90
Texesh
Scratcher
1 post

I can't make my sprite face the direction he is moving.

Change the orientation of the sprites in costumes
bubbyballbounce
Scratcher
2 posts

I can't make my sprite face the direction he is moving.

I'm on mobile and I use the touchscreen to move the character around on my game I'm working on but I want him to look in the direction of his motion so he looks in the direction he moves also there isn't a dpad or anologue stick to move the character. He can be moved with the arrow keys or if you click a button, he goes to the mouse's position or where you tap or you tap and drag, please help me, pointing in the direction doesn't work just to let you know

Powered by DjangoBB