Ask here your questions to get help using GDevelop.
By AnimatedG
#62618 Hi all,

I'm new to Gdevelop and will appreciate some help regarding the direction facing of sprites/objects

I have an object of a space ship and added to the ship event
"add force (angle)"
For direction i set it as : ship.Direction()

It works but for some reason it's flying backwards.
I'm thinking the default direction is set to it's rear. Is there any way to re-set the default direction of the sprite/object?

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

One more question.

Currently it is moving at a constantly +5 pixels per (sec?)

Is there a way to limit the speed?

i'm trying to use:
"Compare the speed when speed >= to 15 "
But not sure what action to use to limit it



Any help will be much appreciated. Thanks :)
User avatar
By Lizard-13
#62623 You can't change the default direction, which is facing to the right, so you have two options:
* Edit the images and flip them so they face to the right
* In every event you get the direction of the ship, add a +180 to the angle to counteract the effect:
Code: Select allAdd a force to the ship, with angle: Ship.Direction() + 180, and length: 5 px/s

I recommend to fix the images, otherwise you'll have to modify every action related to angles :twisted:

If the ship moves constantly at 5 px/s, then its speed is already limited, sorry I don't understand the problem :)
By AnimatedG
#62629 Hi Lizard-13,

Thanks for the help :)

The ship image i used was from the default resource library.
It's default direction (the cockpit) is pointing to the right.

However for some reason it is flying backwards...

Will try a custom image to see if it works correctly

Update: Tried a custom image and it works fine.

----------------------------------------------------------------------------------------------------------------

I'm trying for Asteroid kind of ship controls

After adding force(angle), at length: 5px/s with Dampening:1
The speed keeps keeps increasing per sec which is fine. But how do i limit the speed to say 20/s?

I'm trying the event: Object->Movement->Speed
Overall speed of ship >= 20
But what do i use for the action?

Thanks :)
User avatar
By Lizard-13
#62631
The ship image i used was from the default resource library.
It's default direction (the cockpit) is pointing to the right.
However for some reason it is flying backwards...
Will try a custom image to see if it works correctly
Update: Tried a custom image and it works fine.

Weird, the image should not have any effect in the force direction...

After adding force(angle), at length: 5px/s with Dampening:1
The speed keeps keeps increasing per sec which is fine. But how do i limit the speed to say 20/s?

Ok, so the speed is not constant, I get it. If you set Damping = 1 the force will be stand forever, then you add a new force that will stand forever and so on. This way the forces are added and the total effect will be applied to the ship, this is good for an acceleration process but then you want to limit the ship speed (it reminds me when I tried to do a Star-Control-like ship movement system), a nice way to do it:
* If the thrust button is pressed, add forces to the ship with damping = 1, the ship will accelerate.
* Check if the length of the ship "net force"/average force is greater than 20
* If it's greater than 20, save the ship force angle in a variable with Ship.ForceAngle(), then stop the ship with the "Stop the object" action, and add a force to the ship with force = 20 and angle = saved angle variable

Do you get it? If the ship speed is greater than the limit, replace the ship current forces with an unique force of length = limit and angle = previous average force angle :)
By AnimatedG
#62692 Hi Lizard-13,

If it's greater than 20, save the ship force angle in a variable with Ship.ForceAngle(), then stop the ship with the "Stop the object" action, and add a force to the ship with force = 20 and angle = saved angle variable


Tried this but my ship ends up stopping at speed 20 and accelerates from 0 again.

What could i be doing wrong?
By AnimatedG
#62736 Hi Lizard-13,

Thanks for the zip file.

Tried and getting it to work without stopping at max speed. However, now i'm facing a different problem -_-U

It works correctly when travelling towards the right of the screen but keeps 'bumping' at invisible barrier when going towards the left. Prob due to the acceleration towards the left having to fight the still created Variable(angle) that is present towards the right.

Attached is a pic of the code. Please have a look and see how i'm messing it up XD

2. One more question. I'm having audio latency when shooting sound effect for lasers. The audio file(wav) is trimmed to not contain unwanted silence.

Image
User avatar
By Lizard-13
#62737 1 - The problem is that you save the forces angle in a ship's object variable "angle", but using a scene variable "angle" to add the forces, it should be one of these:
EventOptions.png
EventOptions.png (14.61 KiB) Viewed 1213 times

But never a combination of them ;)

2 - Not sure, how much latency?, is it web?, and what is the audio file size? :?: :?: ... :?: :D
By AnimatedG
#62750 Hi Lizard-13,

It's working fine now! Thank you so much all your help :)

So, there are 3 types of variables?
Global, Scene and Object?

Also, can you please explain Dampening to me?

I initially thought that when Dampening is set to zero it's absolute and when set to 1 it's relative. Doesn't seem to work sometimes for speed etc when set to 0.

Regarding the audio latency issue: The audio file is 119kb wav. Yes, running on html5. Is that why?

Any good documentations to recommend?
User avatar
By Lizard-13
#62760
It's working fine now! Thank you so much all your help :)

Good to know that :)

So, there are 3 types of variables?
Global, Scene and Object?

Exactly! :D
Global: Are kept between scenes, for example remember current level, score.
Scene: Are kept for the current scene only, for example time to finish, helper variables.
Object: Are kept inside each object instance, for example Peter the Phoenix current level.

Also, can you please explain Dampening to me?

The damping is just a multiplier, the force will be multiplied by this damping value each frame.
If the damping is = 1, the force will be multiplied by 1 every frame, i.e. it will be a constant force forever. Useful to add the force only one time, for example you create a bullet, in the same event add a force with damping = 1 and you are done.
If the damping is = 0, the force will work this frame but will disappear in the next one. If you want to move a bullet this way, you will have to add the force (damping=0) every frame.
If the damping is > 1, the force will be greater each frame, even if you apply it only one time. And the force will decrease each frame if 0 < damping < 1. Never tried damping < 0...

Regarding the audio latency issue: The audio file is 119kb wav. Yes, running on html5. Is that why?

Not sure, did you add the sound file in the resources/images manager?, I think the file will be kept in memory if you do it and will play faster. If the audio file is not in the resources manager and you have no idea how to add it, in the images manager select "Add image" and change the extensions filter to view any file, particularly the sound ones :)

Any good documentations to recommend?

Why do you want a documentation if I'm here? :lol: , seriously... the GD documentation is good to start with, then you have the forum and your powerful logic brain :|