改变方向但不影响力



我正在努力解决这个问题,试图增加力量,但没有按照我想要的方式工作,也试图改变方向,但它改变了45度,在我的情况下,这不是我想要的。我正在考虑在arrwos的方向上增加风区,但我来这里是想问是否有其他(更好的(方法。任何帮助都会很棒!谢谢,祝你今天过得愉快!

这是易于理解的图像

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArrowGrass : MonoBehaviour
{
public Rigidbody ball;
public float arrowPower;
public float stoppingPower;
private void OnTriggerStay(Collider other)
{

if (other.gameObject.CompareTag("Player"))
{
Vector3 direction = ball.velocity.normalized;
float speed = ball.velocity.magnitude;
Vector3 currentVelocity = ball.velocity;
Vector3 desiredDirection = new Vector3(-1, 0, 0); // set this to the direction you want.
Vector3 newVelocity = desiredDirection.normalized * currentVelocity.magnitude;
ball.AddForce(newVelocity - currentVelocity, ForceMode.VelocityChange);

/*
ball.angularDrag = stoppingPower;
Debug.Log("Colided");
ball.AddForce(new Vector3(-1, 0, 0) * arrowPower * stoppingPower, ForceMode.VelocityChange);
*/
}
}

}

分离力。

private float userForce = 0f;
void FixedUpdate()
{
if(userForce > 0.1f) // define a minimum force, as we won't reach actual 0.
{ 
userForce *= 0.95; // no need for Time.deltaTime as we are in FixedUpdate!  
}else{
// we can shoot again. User-Force has ended.
userForce = 0; // just make it stop completely eventually.
}
rb.AddForce(userForce * velocity * direction); // you have to define velocity and direction.
}

OnTriggerStay逻辑位于传送带本身,您可以在其中定义力的强度和方向。它应用于Physx系统,并影响玩家刚体的速度。但我们可以跟踪我们的用户力量,同时忽略其他力量。所以球可以继续移动,或者至少被推到墙上等等。

最后,你也可以把同样的原理应用到计时器上。检查时间戳,或者使用Time.deltaTime减少变量并检查它是否<0.

最新更新