I’ll try to move a gameobject, lets say a bullet/projectile, “non-straigtht”.
Normal bullets may fly straight to target, but rockets or something may fly the straight route with some “sinus-irritations”.
Its no problem to calculate some x+1 + sin(). but in case of math.vector3() I dont have any idea.
Also a curve would be nice like “throwing a stone”
Anyone of you ideas? solutions? maybe already done code?
I simply want to modify the fly-route of a weapon
Used my incredible drawing-skills to maybe clearing the situation
My first thoughts for the curve would be to use the physics engine, setting various parameters like drag and the initial kick to the collider should give various types of curved motion, and could get nice landing bounces - if that’s what you’re looking for.
For irritated line, the first idea that comes to mind would be to use a noisy seek target, like a wander behavior that’s moving on a straight line, and your bullet seeks towards it. Might get expensive and probably won’t work with super fast bullets.
Instead, adding a noise value to the axis orthogonal to the flight path of the bullet should do the trick.
Sinus flight appears to be a sin/cos function along the path of the line, exactly like irritated line but replacing the noise function with a sin/cos function.
Giving a GO a force sounds interesting, but these GO in my game are kinematic objects. Not sure if this is possible.
Maybe some else has an idea or code-snipped.?
You don’t want to use physics for movement but you can use it for collision detection if it’s good enough for your game. You could switch to using physics for movement once a collision has taken place. For example, if you have a 2d platformer game where you throw a grenade angry birds style ish after it hits something then you can treat it as a normal physics object which can roll around.
For patterns like sine curves you can apply the curve to the vector direction with some random range applied to it so it looks more organic.
For throwing curves you generally want to look up bezier curves. There are multiple types. You can also apply easing functions to bezier curves. Easing functions (easing equations) can be used for movement too for certain kinds of projectile behaviors.
Irritated line projectile would be a direction vector with a random noise applied to it but you’d probably want a tendency applied to if it the current vector is too far from the original vector it would tend to self correct toward the original vector so that it doesn’t spiral out (unless you want that - maybe if you a shooting a missile you want it to be allowed to more likely spiral out the further it is away from its origin).
Looks very nice and smooth … and… with a couple of parameters to work with. Have to take a closer look to the source to include some of it in my code.
BIG THANKS, like everytime, you did a great support!
By the way…at git… i just can download file by file. There is no “download a zip”-button like in other projects. Why? How do I get/download the whole project ?
The bullet path example is part of my public examples repo consisting of many small examples, all in one single repository. You need to go to the root of the project before you can select Download as Zip.
Sitting Björn sitting at his computer, reading my question here…
… 5min thinking …
… 30 minutes coding …
… done.
sitting me at my pc…
… 1h thinking about live…
… 3h searching for possible ways and commands…
… 6h coding everything found together hoping something will work (and dont know why)…
… 2h trying to understand what this code will do…
… 2d trying to fix the bugs caused by changing my code
just kidding.
I quess I would solved it by myself … but I truly would need hours for it and I quess not this elegant like björn did