Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Apply force to object

A topic by VintageGamerC64 created 16 days ago Views: 25 Replies: 2
Viewing posts 1 to 3

Hi,

for my game i need a function like in the asteroids-game. I tried to rebuilt it. 

The function to rotate was no problem. But when i try to accelarate the spaceship with the apply force to object-function it doesn´t work like i hoped.  The ship is not flying in the direction of the image-angle. What is my mistake ? Please look at this picture. Thank you very much.

Developer

The Ship direction in your sprite is not syncronized with the object angle.

In the event action "aply force to object", try replacing the "angle" expression with one of these:

$Ship.angle + Math.PI/2

$Ship.angle - Math.PI/2

-$Ship.angle + Math.PI/2

-$Ship.angle - Math.PI/2

Math.PI/2 is equivalent of 90º.

(5 edits)

I was just about to give up when i managed it.

The solution for me was to use an object variable, instead of object attribute, for both: rotation and accelaration.
For "Apply force to object" I added an"-" before the "$" and "+Math.PI/2" as you suggested.

So my expression is: -$Ship.getVariable("Angle")+Mah.PI/2     (Ship is my mainobject and Angle the object variable)

Thank you very much for your support.