How do I make "SINE" movement random but always ...

Get help using Construct 2

Post » Fri Jun 24, 2016 3:45 am

Hello Scirra people.

I have a object that is moving with the Sine object.

I want it to go back and forth.

But in the same speed. currently the only way I know how to make it work is with sine is to have a random magnitude, but that makes the object move faster aswell.

is there a way to always make a object move at the same speed but random length?


For example.

It always have a 50 magnitude.

But first time it moves

<------>

Next sine, it moves

<-------------->

(random length)

But always in the same speed.

how do I achieve this?
B
21
S
9
G
8
Posts: 188
Reputation: 6,069

Post » Fri Jun 24, 2016 10:07 am

You have to calculate the period.

Period
The duration, in seconds, of one complete back-and-forth cycle.

Speed = distance / time

So time (period) = speed * distance.
Now distance is in fact the magnitude.
The speed is a constant, thats is what you want, it is some value you choose.

So,
Set magnitude
Set period to speed * magnitude

What i dont know is kinda, when to do it. If you change it middle in the cycle, i suppose it will go weird.
I suppose you have set a new cycle when the expression CyclePosition returns zero.

I idid not test this, just writing whats in my head.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Jun 25, 2016 11:42 pm

Still need help on this!
B
21
S
9
G
8
Posts: 188
Reputation: 6,069

Post » Sun Jun 26, 2016 11:23 pm

Bumping this thread.

Is there maybe a other method?
B
21
S
9
G
8
Posts: 188
Reputation: 6,069

Post » Sun Jun 26, 2016 11:51 pm

Do you need to use SINE movement?

If it's always needing to be the same speed, but vary the distance it travels... it would be easier to create a custom movement for it.

Use bullet behaviour with a set speed, and randomly pick a distance for it to move from it's starting point. Create two instance variables for it's starting spot (X and Y) then create two more for it's destination point (X and Y) and just add or subtract a random value from the destination points... then set the motion towards those destination points.

It's probably easier than trying to mess with over-riding the sine behaviour.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Post » Tue Jun 28, 2016 10:56 pm

SoldjahBoy wrote:Do you need to use SINE movement?

If it's always needing to be the same speed, but vary the distance it travels... it would be easier to create a custom movement for it.

Use bullet behaviour with a set speed, and randomly pick a distance for it to move from it's starting point. Create two instance variables for it's starting spot (X and Y) then create two more for it's destination point (X and Y) and just add or subtract a random value from the destination points... then set the motion towards those destination points.

It's probably easier than trying to mess with over-riding the sine behaviour.

~Sol


I can use whatever works, how would the code look if I had bullet behavior that changed directions like Sine movement?
B
21
S
9
G
8
Posts: 188
Reputation: 6,069

Post » Tue Jun 28, 2016 11:02 pm

- Send the bullet flying forth at (fixed speed)
- Wait (random time)
- Sends the bullet flying back at (fixed speed)
- Wait (twice the previous time)
- Start over
B
7
S
3
G
3
Posts: 56
Reputation: 2,240


Return to How do I....?

Who is online

Users browsing this forum: dop2000, suzannegrey and 29 guests