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
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
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.
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
Why do you want a documentation if I’m here? , seriously… the GD documentation is good to start with, then you have the forum and your powerful logic brain
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)
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
Attached is the error from the console in Chrome if you’re interested to take a look.
Thanks man, really appreciate your help
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
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
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?
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 , 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