How do I figure out a random physics angle

Just started using Construct 2? Post your questions here

Post » Tue Sep 15, 2015 3:16 am

Ok, so my original spawning object is coded like this.

ObjectA Apply Physics Impulse 5 towards random(x,y), random (a,b)
It's the best way I know how to select a point on the map as the area I wanted the object to go, but have a variance so it doesn't always go to that object.

Now, when ObjectA dies, it spawns 2 ObjectB's. I want ObjectB to move at the same angle ObjectA was moving, and then add in a variance on it.

I did this exact thing with Bullet behavior, but of course I had physics problems, so now I am trying to do it with Physics behavior, and well, it's kicking my Butt trying to figure it out. None of the objecta.physics. commands looks like they will tell me the angle of motion. I cant use ObjectA.angle from what I have seen.
B
8
S
1
Posts: 48
Reputation: 524

Post » Tue Sep 15, 2015 10:56 am

when object die make add action and say : system create an ObjectBsame position with ObjectA for examble...
B
17
S
7
G
7
Posts: 205
Reputation: 5,335

Post » Wed Sep 16, 2015 2:10 am

That's just creating it though isn't it? It's not creating the movement or setting the angle
B
8
S
1
Posts: 48
Reputation: 524

Post » Wed Sep 16, 2015 12:24 pm

Well you can get velocityX and velocityY from the physics object, which would give you the moving-angle if needed..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Sep 17, 2015 3:41 am

Tried messing with that some, but I guess I'm not trying the right event action combo. Currently I'm trying to apply an impulse at an angle, and I guess im not sure what I would use within the angle field that would give me the actual angle the first object is moving at. Velocity x and Velocity y I guess just tells you the rate at which an object is moving at the y axis then the x axis... but I dont know how I would formulate that into an angle.
B
8
S
1
Posts: 48
Reputation: 524

Post » Thu Sep 17, 2015 2:26 pm

I guess you could get the angle with this expression:

angle(object.x,object.y,object.x+object.physics.velocityX,object.y+object.physics.velocityY)

But I must admit I'm a bit tired.. haha..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Sep 17, 2015 5:43 pm

Very good stain, that did the trick, now I just gotta play with it to find out the best way to randomize it, and make 2 objects spawn without spawning on top of each other and going flying into random directions
B
8
S
1
Posts: 48
Reputation: 524


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 7 guests