However, the bullets absolutely refuse to work with me, and they never aim for the mouse. Is there something I missed?
I made the formula adjustable to make it possible to shoot multiple bullets in a spread out fan (With adjustable values to bullet spread, bullet amount, etc.)
Unfortunately, the angles of the spread are a little… off.
See, the bullets will only fire in the direction relevant to the FIRST bullet in the fan, rather than the middle of the fan aiming for that angle. For example, the guy in the middle has his bullet amount set to 5, and his firing angle set to 0, and only the bullet at the end of the fan is firing towards angle 0:
So I decided to try and remedy this by adding this extra math to the angle code:
Basically, I want the spread between the bullets to be multiplied by how many bullets are being fired out (In this case, spread of 30 with 5 bullets in the fan = 150), then cut the end result in half (75), then subtract that number from the current angle, to try and ensure that the FAN aims for the angle, not the first bullet spawned.
Here’s the result:
It’s better, but the angle is still a little off. In short, I would like the middle bullet to be shot at angle 0 (Straight to the right).
Can somebody help me out with the nitty gritty, please? I’d greatly appreciate your help ^^
Either as a variable, or directly to guy.angle. Something like :
No, it won’t work. GDevelop does not evaluate a string. If you put a function, like MouseX(), as the value for variable when you define it like this :
it gets treated as a literal string. GDevelop will consider it as “MouseX()”, an 8 character string. It will not set the variable to the value of whatever MouseX() is, it will set it to the literal string.
To set a variable to the value of a function, you need to set it in an event :
This evaluates MouseX(), and puts the resulting value into aimTarget.
I changed the code and got some different results.
The angle now changes, but it only does so at the beginning of the scene, then locks the bullets into shooting in that direction, instead of always shooting towards the mouse.
Also, the angles are really random. It shoots in whatever direction it feels like, depending on the position of the mouse.
What does aimTarget do? And you’re also referencing OGangle in a previous screen snip. Is this interfering with the aiming?
For the firing, you should really be getting and calculating the angle just before you create the bullets. You want a fan, with the middle aimed where the mouse is positioned. So the starting angle should be something like
To rephrase what MrMen mentioned above, since someone else just asked me something similar:
You cannot put expressions (of any type) into a precreated variable field. Expressions only work in events. You are welcome to precreate the variable name but you will have to leave a default value and then set the expression via events.
No, you can’t do that. For one, Variable returns a number. And secondly, even if you used VariableString, GDevelop doesn’t interpret the name at run time. It’s just treated as a string/text, and not as the name of an object.
I think you could achieve what you want by putting all the target objects into a group, and then use the string compare function on the group object name, and get the closest one (though not 100% sure as it’s not something I’ve tried before). Something like :
and then use TargetGroup instead of the object name in the subevents.