0 Favourites

# add force to sprite.angle...?

This forum is currently in read-only mode.
• 6 posts
• 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

• 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.

http://dl.dropbox.com/u/7658043/angular.cap

• 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.

• ## Buy Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• basically i just want to add force where ever the sprite is pointing at.

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.

``````+ 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]``````
• 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.

• I usually use hotspot for stuff like that as math isn'y my strongest area either

• 6 posts
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)