add force to sprite.angle...?

For questions about using Classic.

Post » Fri Mar 11, 2011 10:43 pm

hi ppl!
just a quick question for someone smarter than me:
is it possible to add force to player angle,when using physics behavior?
to make myself clear,when i press up, for example,i want the physics object to move to where its angle is set.
tried some things but i couldnt get it to work,search didnt help either,so anyone willing to help will be praised for years to come :)
B
4
S
2
G
2
Posts: 109
Reputation: 1,318

Post » Sat Mar 12, 2011 12:18 am

What is it exactly that you want to do?.

I made a cap file.Press and hold the up arrow key and the sprite will move upwards.I have set the angle to 270.
[url:1wolvhym]http://dl.dropbox.com/u/7658043/angular.cap[/url:1wolvhym]
B
22
S
3
G
6
Posts: 1,356
Reputation: 7,141

Post » Mon Mar 14, 2011 1:45 pm

thanks for replying! unfortunately thts not what i was going for. basically i just want to add force where ever the sprite is pointing at.lets say the sprite is set to that 270 angle,and the sprite rotates no matter what degrees,now when the up arrow is pressed, the force is added to the sprite's angle,instead of that 270,so the sprite moves to where its angle is pointing at.

so,in short: im trying to make an object,that you can rotate with pressing left and right AND you can move the object forward to where its heading when you press up arrow,using that add force event in physics behavior.

i would use 8 direction or custom movement,but they dont work well with the physics behavior.
B
4
S
2
G
2
Posts: 109
Reputation: 1,318

Post » Mon Mar 14, 2011 2:38 pm

[quote="clodius666":7ph4ap5x]basically i just want to add force where ever the sprite is pointing at.[/quote:7ph4ap5x]
So you just don't know how to calculate the x/y-components from an angle?

That's what the trigonometric functions 'sin' and 'cos' are for. cos(45) returns the x-coordinate of 45 on the unit circle (value between -1 and +1), sin(45) returns the y-coordinate of 45. Just multiply this with the strength you need.

[code:7ph4ap5x]+ MouseKeyboard: On key Up arrow pressed
-> Sprite: Add force (cos(45) * 100, sin(45) * 100)
[/code:7ph4ap5x]

You get the angle of your object using the expression 'Get Angle' (Sprite.Angle)
[code:7ph4ap5x]+ MouseKeyboard: On key Up arrow pressed
-> Sprite: Add force (cos(Sprite.Angle) * 100, sin(Sprite.Angle) * 100)
[/code:7ph4ap5x]
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Mon Mar 14, 2011 2:53 pm

ah, i see. i must admit that math is not my strongest area :)
and never has been,but eh, construct is reason enough to start learning again. its been so long since i had to use any kind of math at all lol.
before i tried to just make a basic command add force to sprite.angle,but it didnt work out that well lol. but thanks for that code,im gonna try it a little later,when i have time.
B
4
S
2
G
2
Posts: 109
Reputation: 1,318

Post » Mon Mar 14, 2011 3:10 pm

I usually use hotspot for stuff like that as math isn'y my strongest area either
B
11
S
3
G
4
Posts: 622
Reputation: 3,186


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests