- Home /
2d kinematic projectile velocity problem
In my game, I have a 2d dynamic rigibody ship that is moving and rotating via addforce() and addtorque(). The ship has a child gameobject (orbital cannon) that can rotate around it, by following and facing the mouse position (ship and orbital cannon movements are calculated inside Fixedupdate).
While the ship is moving, the cannon can still fire 2d kinematic rigibody projectiles in the direction it´s facing but unfortunately, their velocity (direction and speed) is not relative to the ship one. I tried different approaches to solve this:
adding the ship velocity to the projectile one
adding ship velocity magnitude to the projectile speed
other suggestions from forums and unity answers
I would like to avoid using any kind of update or coroutine function to control the projectile velocity or even making it a dynamic rigibody and then firing it using addforce (in a bullet hell game is a performance kill). Here is the current structure I´m using:
//OrbitalCannon.cs spawn function (called inside Update)
private void spawnProjectile()
{
Transform projectile = ProjectilesPool.Spawn("ProjectilePrefab", OrbitalCannon.position, OrbitalCannon.rotation);
ProjectileController prCtr = projectile.GetComponent<ProjectileController>();
prCtr.IntialVelocity = shipRigibody.velocity;
prCtr.projectileSpeed = Speed;
}
// ProjectileController.cs (called when the projectile is spawned)
private void OnSpawned()
{
Vector2 myVelocity = projectileTransform.up * projectileSpeed;
projectileRigibody.velocity = myVelocity + IntialVelocity;
}
I´m also aware of the Doppler effect but if anyone knows how to make the shooting correct and especially natural (like any bullet hell game) please help me. Thank you in advance.
I thought about adding the orbital cannon velocity to the projectile one, but the cannon has no rigibody attached to it. Even so, I need to add a kinematic rigibody to it (nested dynamic rigibody is not the way to go)!! which will make the cannon ignore all the physical interactions.
Your answer
Follow this Question
Related Questions
Need some help with firing projectile at player using Rigidbody Velocity 1 Answer
How do you make a projectile move in an arc? (2d) 1 Answer
Displaying the y value score,Displaying the score of the Y value 1 Answer
Why my rigidbody2D not working when I switch it to dynamic? 0 Answers
Rigidbody2D 0 Answers