Aiming with the mouse now

This commit is contained in:
Norbi Peti 2020-11-20 00:48:50 +01:00
parent 93de3681f0
commit e78ac39841
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
4 changed files with 46 additions and 7 deletions

View file

@ -59,6 +59,28 @@ AnimatorStateTransition:
m_InterruptionSource: 0
m_OrderedInterruption: 0
m_CanTransitionToSelf: 0
--- !u!1101 &-2480231214708551907
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions: []
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 0}
m_Solo: 0
m_Mute: 0
m_IsExit: 1
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.28571433
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1102 &-1640697823006375366
AnimatorState:
serializedVersion: 5

View file

@ -46,7 +46,8 @@ public class OwnCharacterController : CharacterControllerBase
tr.localScale = scale;
}
if (Input.GetButton("Fire3"))
bool sprinting = Input.GetButton("Fire3");
if (sprinting)
input *= sprintSpeed;
if (Mathf.Abs(_rb.velocity.x) <= 3)
@ -56,7 +57,7 @@ public class OwnCharacterController : CharacterControllerBase
{
//_rb.AddForce(new Vector2(0, jumpForce), ForceMode2D.Impulse);
_rb.velocity += new Vector2(0, jumpForce);
if (Input.GetButton("Fire3")) //Csak akkor animálja az ugrást, ha fut közben
if (sprinting) //Csak akkor animálja az ugrást, ha fut közben
{
_jumpStatus = JumpStatus.Up;
_animator.SetInteger(Jump, (int) _jumpStatus);

View file

@ -7,8 +7,8 @@ public class RocketScript : MonoBehaviour
{
private float _fired;
private Rigidbody2D _rb;
private bool _goingRight;
private byte _hitCount;
private Vector2 _forward;
public byte maxHits = 3;
@ -21,8 +21,8 @@ public class RocketScript : MonoBehaviour
private void OnEnable()
{
_fired = Time.fixedTime;
_goingRight = transform.localScale.x > 0;
_hitCount = 0;
_forward = transform.right;
}
// Update is called once per frame
@ -35,7 +35,8 @@ public class RocketScript : MonoBehaviour
_rb.velocity = Vector2.zero;
}
_rb.AddForce(new Vector2(_goingRight ? 10 : -10, 0));
//_rb.AddForce(new Vector2(_goingRight ? 10 : -10, 0));
_rb.AddForce(10 * _forward);
}
private void OnCollisionEnter2D(Collision2D other)

View file

@ -23,10 +23,25 @@ public class WeaponFireController : MonoBehaviour
var theRocket = _pool.GetObject();
var rocketTransform = theRocket.transform;
rocketTransform.position = firePoint.position;
var scale = rocketTransform.localScale;
/*var scale = rocketTransform.localScale;
if (transform.localScale.x * scale.x < 0)
scale.x *= -1;
rocketTransform.localScale = scale;
rocketTransform.localScale = scale;*/
// vector from this object towards the target location
var vectorToTarget = Camera.main.ScreenToWorldPoint(Input.mousePosition) - rocketTransform.position;
// rotate that vector by 90 degrees around the Z axis
Vector3 rotatedVectorToTarget = Quaternion.Euler(0, 0, 90) * vectorToTarget;
// get the rotation that points the Z axis forward, and the Y axis 90 degrees away from the target
// (resulting in the X axis facing the target)
Quaternion targetRotation = Quaternion.LookRotation(Vector3.forward, rotatedVectorToTarget);
rocketTransform.rotation = targetRotation;
Debug.Log("Rotation: " + rocketTransform.rotation.eulerAngles);
/*Debug.Log("Rocket position: " + rocketTransform.position);
Debug.Log("Target position: " + Camera.main.ScreenToWorldPoint(Input.mousePosition));
Debug.Log("Difference: " + direction);*/
theRocket.SetActive(true);
}
}