It looks like you're new here. If you want to get involved, click one of these buttons!

monkeyboy simian
Posts: **423**Member, PRO

@Socks I was trying to work out how you got the actor to start in a particular position in this thread: http://forums.gamesalad.com/discussion/56115/move-in-a-circle I've gone over it and experimented – but can't work it out.

What I'm trying to do is have say 12 actors in a circle. 1 at each place on a clock face. I'm trying to get them to all rotate around at the same time and at the same speed – just not bumping into each other. I think it's possible.

Also am trying to get actors to move along a predetermined path i.e.: snakey – is that possible?

@Socks you mentioned "as I've got it above the object starts at '12 O'clock' and moves clockwise" – Could you please elaborate, is there a way to make it appear in other positions? I've actually got this working as you described. But everytime I try and drag another instance of the actor into the scene it seems to always place it on top of the previous one at the 12 O clock position.

0

## Comments

12,698Member, PROSimply offset the angle of each actor.

This is how we would normally do it (I've used the centre of a Landscape iPad as my size [512, 384]).

X pos =200

`*`

cos(angle)+512Y pos = 200

`*`

sin(angle)+384The angle defines where in the orbit the actor appears, if we want the actor to move around the orbital path we would need a changing value (so the actor is at 1° then 2° then 3° then 4° . . . .and so on), for this the lazy option is just to use self.time for the angle, as this is a ready made value that always rises (1 second, 2 seconds, 3 seconds . . . . ).

But a better, more flexible approach would be to use a separate controller actor for the angle, just an actor that is rotating.

We can then use this controller actor's angle to drive our expression

X pos = 200

`*`

cos(controller's angle)+512Y pos = 200

`*`

sin(controller's angle)+384So, if you you want 12 actors all separated by 30°, you simply need to add that value (the offset) into each actor . . .

So actor one would be . . .

X pos = 200

`*`

cos(controller's angle)+512Y pos = 200

`*`

sin(controller's angle)+384Actor two would be . . .

X pos = 200

`*`

cos(controller's angle+30)+512Y pos = 200

`*`

sin(controller's angle+30+384Actor three would be . . .

X pos = 200

`*`

cos(controller's angle+60)+512Y pos = 200

`*`

sin(controller's angle+60+384Actor four would be . . .

X pos = 200

`*`

cos(controller's angle+90)+512Y pos = 200

`*`

sin(controller's angle+90+384. . . and so on . . .

An example file is attached below.

How are you generating the path

423Member, PROwow, thanks @Socks – that's exactly what I'm talking about.. amazing.. and I love the colour shift. It seems to me that this cos and sin can do a lot. I really struggle to understand those things. Re the path – I don't know how I'd actually instruct it to do so.

12,698Member, PROWhat does the path look like ?

423Member, PRO@Socks I was thinking of making random paths.. For example winding paths that snake across the screen. I was hoping to make paths in a vector drawing program and use them as guides. I suspect that this isn't possible. I suspect that this would involve a lot of cos and sin action.

Edit: I just found this tutorial which does use cos and sin to move actors along a path:

I think this could be what I need to do..

12,698Member, PROAttached is one approach to random winding paths . . .

423Member, PROThat's impressive.. I don't know how you think of these things. But thanks @Socks. I've been trying to get a better understanding of cos and sin with some YouTube tutorials – but it's still boggling to me.

I was wondering, when the expression is referring to time – is that the rate of movement of the actor? Is there a default rate/speed? Because it appears that you're multiplying time.

Armelline seems to be doing the same thing in his video. I think I have to play around with what you've done.

This has made me wonder whether would you can use cos and sin for curved paths only – or could you say, make the same actor move along and "draw" a triangle, a square etc? Is it possible to have precise control of where it moves?

I've been tinkering with the Rnd attribute with no apparent changes in behaviour – what's it for?

PS: watching that little actor move around is quite hypnotic – you could probably make an interesting piece of evolving art with that...

12,698Member, PRONo, time refers to the

angleon which sin or cos is operating.When you use cos or sin you need to supply it an angle on which to operate, you need to have the cos of something or the sin of something, that something is an angle.

When you use the calculation . . . . cos(X) . . . you are asking GS to tell you what the cosine of the angle in the brackets is.

Check out the GS demo file attached, it shows you how cos and sin relate to angles.

If you grab the white dot that sits on the edge of the circle and drag it around . . you can change the angle of the white line.

Once you have arrived at an angle (choose any angle you like) you can see that that angle has both a cosine value (shown by the red line) and a sine value (shown by the blue line).

The cosine is very simply the horizontal distance from the centre of the circle to the point on the edge where the line hits it. The same deal with sine, the sine is very simply the vertical distance from the centre of the circle to the point on the edge where the line hits it. Cosine = X . . . . Sine = Y

So we say . . . . (examples):

the cosine of 35° is 0.819

the sine of 110° is 0.94

the cosine of 110° is -0.342

the cosine of 0° is 1

the sine of 170° is 0.174

. . . etc etc

Or to put it mathematically/in GS syntax:

cos(35)=0.819

sin(110)=0.94

cos(110)=0.342

cos(0)=1

sin(170)=0.174

. . . . etc

Hope that makes sense.

. . . . . .

Not sure I understand the question ?

Again, I'm a little confused about the question ?

It randomises the path, if you switch it off the path will always be the same, every time you preview the project the path it will trace out will always be the same path. The Rnd value adds a random value to the angle that cos and sin are operating on.

Attached are a couple of evolving art pieces . . . .

423Member, PRO@Socks .. I need some time to go over what you've said here (I am extremely grateful, by the way). But before I dive into this with my limited time, I just have to say that those evolving art things are amazing.

The Loop8 is to me, inspired. It makes me wonder what you could do if you invested more time. I can see an amazing "game" in that. And the accompanying sound is beautiful – the whole thing is to me, demonstrative of what great potential GS has and in the right hands, what amazing creative outcomes can be had. Have you made any games? You should, really, you should!

PS: Why would they call it time if it's referring to the angle?

12,698Member, PROI will eventually (I hope!)

sin (X) . . . .

This calculation looks what is in the brackets and then gives you the sine of that angle.

So for example the sine of 45° is 0.7071 . . . which in maths is expressed like this: sin(45).

So if you stick sin(45) into a calculator, or GS (or anywhere like that) it will give you '0.7071'.

But in most scenarios (like in GameSalad) people are usually after a changing within the brackets, for example an actor moving in a circle would want the value to be constantly changing . . .

A quick and easy way to conjure up a changing value is to just stick self.time or game.time in as the angle - it's a ready made value that always rises - so you can cheat and use this as the angle, throw self.time in there and you have a ready made angle value that is always rising.

But seeing as game.time or self.time counts up by 1 every 1 second (it is after all a clock), that means it would take 10 seconds for the angle to change from 0° to 10°, and a whole 360 seconds for the angle to go from 0° to 360°, which is 6 minutes !!! And seeing as most people - when doing stuff for games - want something to orbit or rotate a lot quicker than 1 revolution every 6 minutes they will simply multiply self.time by something to speed it up.

So whereas this would see your actor follow a 400 pixel wide orbit in 6 minutes.

constrain x to 200

`*`

cos(self.time)constrain y to 200

`*`

sin(self.time)This would see it do the same thing in 3.6 seconds

constrain x to 200

`*`

cos(self.time`*`

100)constrain y to 200

`*`

sin(self.time`*`

100)tl;dr using time is a quick and easy cheat, with time we get an ever rising value, we can do what we want with that value, in this case we use it to represent an angle.

423Member, PROThanks for the explanation @Socks.. My understanding of this has improved thanks to you (and I'm sure others reading this thread in the future will too), though sadly I feel that I'll probably never understand this stuff completely. I only figured out that this is trigonometry because your file name "trig2" made me curious and I googled it. I never studied this stuff at school and now I'm regretting it as I can see how you can do amazing things with it

if you know how to use it.I've gone through your "Loop8" and "Loop0" files and just can't work out how you managed to make the actors move in those ways. I can't even work out how you got the little markers on your "trig2" file to space out so evenly.

I think my chances of achieving that level of control are slim... I'm already stretching the limits of my dusty neural paths. I've tried youtube tutorials on cos and sine over the last few days, but I just can't see how you can do what you did.

I've got something to go on here though – which is very helpful – I just wish I could

understandit better so I could build on it rather than just copying you.Above I mentioned the idea of making actors draw out more precise shapes:

@monkeyboy simian said:This has made me wonder whether would you can use cos and sin for curved paths only – or could you say, make the same actor move along and "draw" a triangle, a square etc? Is it possible to have precise control of where it moves?

And you weren't sure of what I meant... I was imaging and actor or actors moving much like they would in a circle (as you so deftly demonstrated).. but not in a circular shape.. i.e.: squares or triangles, diamonds etc.. I'm thinking cos and sine don't factor into this idea.

12,698Member, PROI just spaced them 5° apart using cos/sin, it's not difficult, even though it might seem difficult if you are not familiar with cos/sin.

I doubt that, it's a lot simpler than you might think, just get a basic move going and play around with the values until you've got something you like !

I'd avoid youtube tutorials on cosine and sine, then tend to bog you down with esoteric language, even terms like 'hypotenuse' switch my brain off, the more of these terms ('secant', 'the reciprocal of the cosine' . . .etc ) a video has the more I switch off.

If I were you I would simply learn what cos and sin are, and how to use them (for good as well as evil), that's all you need to do lots of useful stuff in GameSalad.

I could teach you the basics if you want. They are about as difficult as X, Y coordinates.

Yeah, that's not something cos / sin would really help with, there are far more straightforward ways to achieve an actor moving in a square / diamond / triangle . . .

For example, a triangular path:

Move behaviour / 0° / Relative to Actor

Timer Every 2 seconds

--Change Rotation to Rotation +120

423Member, PROI'd appreciate any assistance that you're prepared to offer – I've discovered after doing this since 2012 that my brain is really lacking here.

I was wondering why you've multiplied cos and sin by 310 in the trig file – see grab below..

In this grab below – is this where you're spacing the clicker markers out by 5° (By the way, I had to google how to get the degrees symbol )

By the way, I remembered a game that your "Loop8" reminded me of. Are you familiar with "Groove Coaster" there's also a "Groove Coaster 2" now.

12,698Member, PROSine and cosine operate between the values -1 and +1, this has nothing to do with GameSalad or anything like that, it's just the way the maths works.

Take a look at the trig2 file again, drag the angle around and watch how the cos and sin values swing between -1 and +1.

So . . . . these values aren't much use to people who make stuff for mobile devices (unless your game is very very small), so we tend to multiply them to make the values bigger.

Yes !

Just like everyone else ! There's no secret 'how to get the degrees symbol' class you missed I used to cut and paste it from Google for years before I got bored and looked up how to type it (swipe up on the zero number key on iOS / Shift+Alt+8 on OSX)

I'm not, but I'll definitely look it up.

Sure, no problem, maybe I'll start a new thread ?

423Member, PRONew thread sound good to me.. I checked the trig file. I hadn't really focused on the actual values tiny numbers – I guess it's like that for a reason. So you could've multiplied it by say, 150. I'll have to play around with it during my next session. Oh, and I'm glad I actually worked something out re the 5°..

12,698Member, PROOf course, that'd simply give you a smaller circle !

423Member, PRO@Socks more progress.. I tried it and it indeed it did shrink.. Just wondering.. I tried turning off some of the marks + clicker spawn actors etc, yet it still displayed the same amount – what gives?

Just tried this:

Move behaviour / 0° / Relative to Actor

Timer Every 2 seconds

--Change Rotation to Rotation +120

which you mentioned. I feel like this:

hence my name.

yup.

12,698Member, PROTake a look at this (assume X starts out at 0) . . . .

If X is less than 10 . . . then do the following Every 0.1 seconds.

--Spawn an actor

--Change X to X+1

Ok, that's version 1, now for version 2 . . . .

If X is less than 10 . . . then do the following Every 0.1 seconds.

--Spawn an actor

--Change X to X+1

--Spawn an actor

--Change X to X+1

--Spawn an actor

--Change X to X+1

--Spawn an actor

--Change X to X+1

--Spawn an actor

--Change X to X+1

If you look at the logic of each version you'll see they both spawn 10 actors, but version 2 does this 5 times faster than version 1, in 1 tenth of a second version 1 spawns 1 actor, whereas in 1 tenth of a second version 2 spawns 5 actors.

Now imagine what happens to version 2 if you were to delete all the extra instructions (so it essentially becomes version 1), it will still spawn the same amount of actors, just not as rapidly.

Obviously the outside angles of am equilateral triangle are 120°, so taking a 120° turn at regular intervals will trace out a triangular path, the same deal with any regular shape, simply divide 360° by the number of sides you want, to move in a square you will need to take a 90° turn every X seconds, for a pentagon it'll be a 72° turn . . . etc etc.

423Member, PRO@Socks I think I understand what you mean with the change x to x+1 thing – but I still don't understand why you have multiple spawners all doing the same thing. If you turn one off, it still spawns the same amount of marks.

PS: Am looking up equilateral triangles and their outside angles (not obvious to me – told you I was not the brightest)

12,698Member, PROYes, as it should !

I'll put another way . . . . goal, keep going to the grocery store and buying apples until you have 10.

Version one of our rule.

--If the apple barrel contains less than 10 apples

----Go to the store and buy an apple

Version two of our rule.

--If the apple barrel contains less than 10 apples

----Go to the store and buy an apple

----Go to the store and buy an apple

----Go to the store and buy an apple

----Go to the store and buy an apple

----Go to the store and buy an apple

In version one the person checks the barrel, if there are less than 10 apples he goes to the store, buys an apple, comes back, throws it in the barrel . . . then he checks the barrel, if there are less than 10 apples he goes to the store, buys an apple, comes back, throws it into the barrel . . . and so on until he has ten apples in the barrel.

In version two the person checks the barrel, if there are less than 10 apples he goes to the store, buys an apple, buys an apple, buys an apple, buys an apple, buys an apple . . . comes back, throws all 5 apples into the barrel . . . then he checks the barrel, if there are less than 10 apples he goes to the store . . .

Version 1 takes 10 trips to the grocery store to get all 10 apples, version 2 take just 2 trips.

Now . . . to the question of

"If you turn one off, it still spawns the same amount of marks.".Look at the second version of the apple rules, if you were to get rid of four of the five 'Go to the store and buy an apple' rules, the barrel will still get filled with 10 apples.

Hope that makes sense.

Well, maybe it's not obvious, but it's something that anyone can work out, the outside angles must be

something, that's enough to realise that you need to rotate a moving actor by whatever thatsomethingis to trace out a triangle !423Member, PRO@Socks – So these four spawners are to speed up the spawning? One would suffice, but more is better... in order to speed it up?

12,698Member, PROExactly !

423Member, PRO@Socks wow – I actually got it... I think. Thanks for your patience. I've got a lot to digest here.

423Member, PRO@Socks .. Regarding the actor moving in a triangular path etc (which works a treat), I'm trying make multiple other actors all follow the exact same path, behind the original one (although at this stage I'm just trying to make one follow).

I've tried constraining to x and y game level attributes but the following actor follows as if it's joined to the leader – even though I've placed it away from the leader (about 30 pixels).

The following actor is an instance of the leader actor which I've unlocked on the scene to ensure that it's starting position is offset from the leader.

12,698Member, PROHow did you place it 'away from the leader' ?

423Member, PRO@Socks I just dragged it there from the window where the actors are kept on the left. It's the same actor as the leader actor only I've dragged another instance of it there.

It's weird – because it starts out there but when I play/preview it, it's like this

12,698Member, PROI see . . . . [scratches his chin like a doctor, fumbles under the desk for the alarm button] . . . . in GameSalad you need to give an actor a specific instruction to behave how you would like it to behave rather than position the actor in a certain way (next to another actor for example) and then hope this information will be reflected in the actor's behaviour.

"I've tried constraining to x and y game level attributes but the following actor follows as if it's joined to the leader"Constrain means to 'force' something, so to constrain an actor's position to a certain value means the actor will always be at that position . . . . in this case you are asking GameSalad to constrain this actor to the leader's position, so it will appear to be joined to the leader (technically speaking, on every frame of the code this actor will be told to position itself in the same place as the 'leader').

Another way of looking at the constrain behaviour is to see it as a Change Attribute behaviour that is always firing, it constantly checks what it is meant to be changing its value to and then changes it, every 1/60th of a second.

423Member, PRO@Socks .. oh. I tried a "move to" behaviour which works – sort of. It follows as should but it cuts the corners so to speak – which makes sense. The leader actor is travelling along a triangle path, and the idea is that the follower follows exactly the same path – without cutting the corners. Theoretically, I'd like to apply this to other shapes i.e: circles, squares etc.

I've tried all of the other behaviours I can think of or look like they might do the job – and none of them do. I'm starting to think that this isn't possible.

PS: I found this thread from a while ago http://forums.gamesalad.com/discussion/88246/how-can-an-actor-follow-an-another-actor-moving-in-circle

You don't seem to be using game attributes here to make this happen.. I know it's a circle – but I thought that it was still necessary because everything I find in the forums seems to want to use them too.

This is doing my head in.. surely this is possible?

2,724Member, Sous Chef, PROIf you want to have an actor follow another's path, you can record the x,y positions of the 'leader' actor. Then you have the 'follower' move to those recorded positions. Here is an example.

12,698Member, PROIn GameSalad it's likely that for each case (triangle, circle, star, rectangle . . . etc) you will probably be better off using a particular solution designed for that shape.

Everything is possible !

Game attributes are for losers

If I remember correctly that example is using an angle offset to define the path of the second (following) actor, think of it like a clock, actor 1 is following the second hand, actor 2 is following the second hand + 5 seconds.

Hope that makes sense !

1,369Member, PROYou can spawn an invisible actor when the rotation takes place , it should work for any movement as well except for circle (i think) and you don't need any additional attribute.