- Home /
bullet follows target and arcs with sin
Hello,
I have a bullet that must follow player and rotate bullet graphics so that bullet appears to move forward.
I do this like this:
transform.rotation = Quaternion.LookRotation(Vector3.forward, transform.position - _target.collider2D.bounds.center);
transform.position = Vector3.MoveTowards(transform.position, _target.collider2D.bounds.center, flySpeed*Time.deltaTime);
what I want to achieve now is that bullet does not move in a straight line but sort of arcs up and down while tracking the player. Sort of like a sine movement applied to it.
I managed to do that with this code:
transform.rotation = Quaternion.LookRotation(Vector3.forward, transform.position - _target.collider2D.bounds.center);
Vector3 _targetRotation = transform.eulerAngles;
float _rotationAddon = Mathf.Sin (Time.realtimeSinceStartup)*sinSpeed;
_targetRotation = new Vector3(_targetRotation.x, _targetRotation.y, _targetRotation.z+_rotationAddon);
transform.eulerAngles = _targetRotation;
But when I use this I can't find a proper movement code that will move the bullet forward based on angle and does not look weird if it has to turn 90+ degree angles when tracking the player.
has anybody done something similar?
Thanks in advance
any reason
transform.position += transform.forward * flySpeed * Time.deltaTime;
doesn't work?
u could factor in Physics.Gravity if i'm correct in assu$$anonymous$$g ur asking for bullet Coriolis effect(real bullet physics).
Your answer
Follow this Question
Related Questions
how to stop the camera to follow the player on his jump movement ? 2 Answers
Camera rotation around player while following. 6 Answers
How to make one game object follow another? 1 Answer
Getting an Object to follow a Sine Curve 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers