Changing Default Sprite/Object Direction

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 :slight_smile:

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:
Add 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 :smiling_imp:

If the ship moves constantly at 5 px/s, then its speed is already limited, sorry I don’t understand the problem :slight_smile:

Hi Lizard-13,

Thanks for the help :slight_smile:

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 :slight_smile:

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

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 :slight_smile:

Hi Lizard-13,

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

What could i be doing wrong?

Check this: (3.45 KB)
If you can’t find why this works and yours not, let me see some code :slight_smile:

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

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

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:

But never a combination of them :wink:

2 - Not sure, how much latency?, is it web?, and what is the audio file size? :question: :question::question: :smiley:

Hi Lizard-13,

It’s working fine now! Thank you so much all your help :slight_smile:

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?

Good to know that :slight_smile:

Exactly! :smiley:
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.

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…

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 :slight_smile:

Why do you want a documentation if I’m here? :laughing: , seriously… the GD documentation is good to start with, then you have the forum and your powerful logic brain :neutral_face:

Hi Lizard-13,

Thank you for the explanation on variables and Dampening. Makes things much clearer now :slight_smile:

Will try adding the audio to the resource manager.

Thanks for being so helpful and quick on the replies. Didn’t want to keep bothering you with trivial questions if i can solve it by reading up on them :slight_smile:

That being said, can i trouble you with this 2 problems i encountered?

Only one instance of object enemytroop is firing, when i have more that one instance on screen.

I’m trying to have the ship stay in invincible state (no collision hit box)
for 3 secs after being damaged

For some reason, the game freezes after i re-pause the timer “invincibility”
after 3 secs are up

The ‘normal’ state of ship = animation 0
Invincibility state = animation 1

Classic, you can read about it here (choose one):
[url]Problem with Enemys Firing]
[url]multiple spawned bots but only one shoots]
[url]Turret fire]

So it doesn’t crash when you switch to the animation with no collision mask, but crashes when you switch back to the default animation?, not sure, try to add a collision mask to the invincible animation and let me know if still crash.
Also, what is the error in the console? (in Firefox, you can open the console with Ctrl+Shift+I or Ctrl+Shift+K) :slight_smile:

Hi Lizard-13,

Still having the same trouble with only one enemy firing even after trying the variable timer. Is it because no specific instance (enemy) is specified and hence the creation point for all blasts are created at the same enemy instance?

The crash was from the lack of collision box. Stopped crashing after i added one :slight_smile:
Attached is the error from the console in Chrome if you’re interested to take a look.

Thanks man, really appreciate your help :slight_smile:

Here’s what i did to make an invincible state instead in case someone else is having the same issue.

Created for the ship a variable - shipstate
‘Normal’ state - shipstate = 0
‘Invincible’ state - shipstate = 1

Created timer - invincibility
At beginning of scene - pause timer ‘invincibility’

Collision with asteroid and shipstate = 0 - Ship damage
set shipstate = 1

when shipstate = 0 - change animation to ‘normal’ animation
when shipstate = 1 - change animation to ‘invincible’ animation
unpause timer ‘invincibility’

when timer ‘invincibility’ is greater than 3 secs - set ship state = 0
pause timer ‘invincibility’
reset timer ‘invincibility’

You specify instances with the timer variable checking, but maybe you are right: Multiple enemies (if not all) could met the condition at the same time, because all the enemies start with variable “fire” = 0 at the beginning of the scene, then just one blast is created for all of them.
Easy fix, add a “Fore each enemy” to make sure one instance is checked at a time:

For each enemy: Conitions: Variable fire of enemy is >= 2 Actions: ...
The event “Always >> do + TimeDelta() to the variable fire of enemy” doesn’t need a For each loop.

A state variable is a great solution :slight_smile:

About the error, I can barely see where it comes from and why it crashes, as the collision mask is undefined GD thinks that the collision mask is the default one, and tries to set the default hitbox points (to make the box), but the mask has no points so it crahes here.
What a mess eh? :smiley:

Hi Lizard-13,

Thanks! Using ‘For each object’ worked!
For those having trouble finding ‘For each object’, it’s under ‘other’ where you will find ‘add event’ and ‘a sub event’

I attached a pic to make it easier to find

Tried this but it didn’t work. Maybe i’m doing it wrong. Is it to just add ‘Always’ to the condition of the ‘+TimeDelta’ part?

Thanks for pointing out it 's due to missing hitbox. I’m just glad there is a work around for it :slight_smile:

Always or no conditions, it’s the same, as you did in the pic :slight_smile:

Hi Lizard-13,

I’m trying to randomize the firing rate of the troops by doing

Variable firerate of enemytroop  >= Random(2) +1

But it’s not working. It seems to be treating Random(2) as non- existent .

I’m now using a roundabout way of doing this by:


Variable firerate of enemytroop >= 1 || Do = Random(2) to variable randomfire of enemytroop
Do = 0 to variable firerate of enemytroop
(sub-event) Variable randomfire of troop = 1 || Create object blast at enemytroop.X() enemytroop.Y()[/code]

Is there a better way of doing this?

Also, is there a way to have the BGM persist throughout different scenes?

I explain the why here: [url]why random(a)+b does not working for timers?]
I talk about the problem with the evaluation of Random() every frame, now in the linked topic we are talking about a global timer and fix it with a global variable, you have instance timers so you’ll need an instance variable.
Ok, I see that you already use an object variable for the random value, it’s the best per-instance approach :smiley: , now I would suggest this change, so you don’t need a sub-event per random option:

[code]Conditions: Always (no conditions)
Actions: Do + TimeDelta() to the variable “firerate” of enemy

For each enemy:
Conditions: Variable “firerate” of enemy is >= enemy.Variable(randomfire)
Actions: Create bullet, move bullet, etc.
Do = 0 to the variable “firerate” of enemy
Do = Random(2) + 1 to the variable “randomfire” of enemy[/code]

Check the scene options (right click on the scene, and “Edit the properties”), there is a checkbox with the option “Stop all sounds and musics at startup”, and it seems it’s enabled (stop sounds) by default, disable it in every scene you want to keep the previous music. I hope it works, because there have been some problems concerning this in the past :slight_smile:

Hi Lizard-13,

Thanks! That works way cleaner :slight_smile:
Ah, that makes a lot of sense regarding the random timer

BGM working well too now! Thank you