Rotate Object W/o Changing Direction

Get help using Construct 2

Post » Thu Aug 01, 2013 2:53 am

Possible for a sprite with bullet behavior or another way?

Basically want to set random orientation at start, but still want it to go down or at 90 degrees with the bullet behavior.

Just trying to introduce some randomness, so it all does not look so uniform.

I've tried like 5 different things so far and nothing is working.

I know it's possible with a player sprite via orienting toward the mouse cursor while moving in another direction.
B
30
S
17
G
12
Posts: 215
Reputation: 9,301

Post » Thu Aug 01, 2013 3:11 am

i'm not sure i understand what you want.

do you want enemies coming from top of the screen and go down but flying in weird pattenrs??or just spinning around?
B
4
Posts: 24
Reputation: 248

Post » Thu Aug 01, 2013 3:14 am

Well, all the sprites would be going down or at 90 degrees, but I want them oriented or turned at a random angle.

So say you have a sprite in the shape of a cross, instead of all crosses looking nice and uniform, they would be rotated by various degrees but still heading down.
B
30
S
17
G
12
Posts: 215
Reputation: 9,301

Post » Thu Aug 01, 2013 3:25 am

Animation frames?
B
22
S
4
G
1
Posts: 100
Reputation: 2,150

Post » Thu Aug 01, 2013 3:40 am

With Bullet behaviour set the "Set Angle" property to no, then when you set the angle of motion the sprite wont move (change angle direction I mean).GenkiGenga2013-08-01 03:41:40
ImageImage
B
109
S
23
G
7
Posts: 1,062
Reputation: 12,708

Post » Thu Aug 01, 2013 3:54 am

@GenkiGenga

I tried that:

I have a Sprite with the bullet behavior. I Set Angle to "No".

Then:

Sprite -> Rotate random (360) toward random (layoutwidth), random (layoutheight).

Sprite -> Set Angle to 90

And they're still all pointing upright.

I tried Rotate Toward Angle, Rotate Toward Position, Set Angle, and Set Angle Toward Position all to no avail. All the sprites are still pointing straight up/down, the direction they're moving in.

@klkitchens

I also can't figure out how to pick a random frame for a sprite out of a set of its frames.

I have a 54 frame sprite.

I did a global or local FrameNo=0 for starters.

Then:

System -> Set FrameNo = floor(random(55))

Sprite - > Set Animation Frame to FrameNo

And nothing works.

B
30
S
17
G
12
Posts: 215
Reputation: 9,301

Post » Thu Aug 01, 2013 4:12 am

Is this the kind of thing you are looking for?

http://db.tt/gd9KSdf7

ImageImage
B
109
S
23
G
7
Posts: 1,062
Reputation: 12,708

Post » Thu Aug 01, 2013 4:57 am

@AmpedRobot

https://dl.dropboxusercontent.com/u/7409023/construct/DropRandomFrame.capx

Seems to work just fine.

Made a sprite with just four frames, then Created the Sprite and set animation frame to floor(random(4))
B
22
S
4
G
1
Posts: 100
Reputation: 2,150

Post » Thu Aug 01, 2013 6:18 am

Wow, thank you both.

My mistake on randomizing the sprite angle was assuming any of the sprite set angle options would work correctly with the bullet behavior whereas apparently the secret with setting the angle to "no" on the behavior was then to use the Set Bullet Angle of Motion. The code example I had was with "yes" which used the default initial angle from the sprite's properties, so I thought that was enough even with the "no" setting. Things like that are not immediately obvious to a newbe.

On the second example, for randomizing the frame, apparently using the random function directly in the Set Animation Frame was the secret as opposed to linking it to a global variable. Since it was a sub-action with a system repeat function I thought it would reroll the variable on every spawn, but apparently not.

Programs are sometimes picky and this one incredibly so (but no more than several others I've been learning).

In any case, thanks again. You saved me hours of experimentation and frustration I would have had to go through tomorrow and I will use these functions for many things.

If we had a central repository of working, useful code examples (as opposed to just searching the forums, which is often a miss), that might be worth the price of the software or more.
B
30
S
17
G
12
Posts: 215
Reputation: 9,301


Return to How do I....?

Who is online

Users browsing this forum: anty21ro, BackendFreak, HellMax and 9 guests