У меня есть проект Unity. Защищенная переменная вектора2 (скорость) в абстрактном классе (MovementAgent), используемой агентом, который наследует от этого класса. Ошибки. < /p>
public abstract class MovementAgent : MonoBehaviour where T : MovementAgentSO
{
protected Vector2 _velocity;
protected Vector2 velocity { get => _velocity; set => _velocity = value; }
public Vector2 GetVelocity() => velocity;
[NonSerialized] protected T Settings;
///
/// Initializes the MovementAgent to use the settings ScriptableObject provided as a parameter.
///
/// Settings ScriptableObject reference
public void Initialize(T settings)
{
Settings = settings;
}
///
/// Processes the movement of the agent and keeps its rotation aligned with its velocity.
///
protected void ProcessMovement()
{
if (velocity.magnitude > Settings.maxSpeed)
{
velocity.Normalize();
velocity *= Settings.maxSpeed;
}
transform.rotation = Quaternion.Euler(0, 0, (float)(Math.Atan2(velocity.y, velocity.x) / Math.PI * 180));
transform.position = (Vector2)transform.position + velocity * Time.deltaTime;
}
public Vector2 Seek(Vector2 target)
{
Vector2 desiredVelocity = target - (Vector2)transform.position;
desiredVelocity.Normalize();
desiredVelocity *= Settings.maxSpeed;
Vector2 turnVector = desiredVelocity - velocity;
if (turnVector.magnitude > Settings.maxTurnSpeed)
{
turnVector.Normalize();
turnVector *= Settings.maxTurnSpeed;
}
return turnVector;
}
public Vector2 Arrive(Vector2 target, float radius)
{
Vector2 difference = target - (Vector2)transform.position;
float distance = difference.magnitude;
if (distance > radius) return Seek(target);
Vector2 desiredVelocity;
if (radius == 0)
desiredVelocity = difference.normalized * Settings.maxSpeed;
else
desiredVelocity = difference.normalized * (Settings.maxSpeed * distance / radius);
Vector2 steering = desiredVelocity - velocity;
steering = Vector3.ClampMagnitude(steering, Settings.maxTurnSpeed);
return steering;
}
public Vector2 Flee(Vector2 target)
{
return -Seek(target);
}
public Vector2 Pursue(Vector2 target, Vector2 targetSpeed, float predictionTime)
{
return Seek(target + targetSpeed * predictionTime);
}
public Vector2 Evade(Vector2 target, Vector2 targetSpeed, float predictionTime)
{
return -Pursue(target, targetSpeed, predictionTime);
}
public void AddVelocity(Vector2 velocityToAdd)
{
velocity += velocityToAdd;
}
public float GetMaxSpeed()
{
return Settings.maxSpeed;
}
}
< /code>
Если я шагаю по кадру за кадром на Unity, я вижу, как пара пустот внезапно начинает двигаться с большими приращениями, выходя за пределы диапазонов поплавок всего за пару кадров. Заранее спасибо!>
Подробнее здесь: https://stackoverflow.com/questions/797 ... s-an-error
Изменение переменной на свойство создает ошибку ⇐ C#
Место общения программистов C#
-
Anonymous
1757853932
Anonymous
У меня есть проект Unity. Защищенная переменная вектора2 (скорость) в абстрактном классе (MovementAgent), используемой агентом, который наследует от этого класса. Ошибки. < /p>
public abstract class MovementAgent : MonoBehaviour where T : MovementAgentSO
{
protected Vector2 _velocity;
protected Vector2 velocity { get => _velocity; set => _velocity = value; }
public Vector2 GetVelocity() => velocity;
[NonSerialized] protected T Settings;
///
/// Initializes the MovementAgent to use the settings ScriptableObject provided as a parameter.
///
/// Settings ScriptableObject reference
public void Initialize(T settings)
{
Settings = settings;
}
///
/// Processes the movement of the agent and keeps its rotation aligned with its velocity.
///
protected void ProcessMovement()
{
if (velocity.magnitude > Settings.maxSpeed)
{
velocity.Normalize();
velocity *= Settings.maxSpeed;
}
transform.rotation = Quaternion.Euler(0, 0, (float)(Math.Atan2(velocity.y, velocity.x) / Math.PI * 180));
transform.position = (Vector2)transform.position + velocity * Time.deltaTime;
}
public Vector2 Seek(Vector2 target)
{
Vector2 desiredVelocity = target - (Vector2)transform.position;
desiredVelocity.Normalize();
desiredVelocity *= Settings.maxSpeed;
Vector2 turnVector = desiredVelocity - velocity;
if (turnVector.magnitude > Settings.maxTurnSpeed)
{
turnVector.Normalize();
turnVector *= Settings.maxTurnSpeed;
}
return turnVector;
}
public Vector2 Arrive(Vector2 target, float radius)
{
Vector2 difference = target - (Vector2)transform.position;
float distance = difference.magnitude;
if (distance > radius) return Seek(target);
Vector2 desiredVelocity;
if (radius == 0)
desiredVelocity = difference.normalized * Settings.maxSpeed;
else
desiredVelocity = difference.normalized * (Settings.maxSpeed * distance / radius);
Vector2 steering = desiredVelocity - velocity;
steering = Vector3.ClampMagnitude(steering, Settings.maxTurnSpeed);
return steering;
}
public Vector2 Flee(Vector2 target)
{
return -Seek(target);
}
public Vector2 Pursue(Vector2 target, Vector2 targetSpeed, float predictionTime)
{
return Seek(target + targetSpeed * predictionTime);
}
public Vector2 Evade(Vector2 target, Vector2 targetSpeed, float predictionTime)
{
return -Pursue(target, targetSpeed, predictionTime);
}
public void AddVelocity(Vector2 velocityToAdd)
{
velocity += velocityToAdd;
}
public float GetMaxSpeed()
{
return Settings.maxSpeed;
}
}
< /code>
Если я шагаю по кадру за кадром на Unity, я вижу, как пара пустот внезапно начинает двигаться с большими приращениями, выходя за пределы диапазонов поплавок всего за пару кадров. Заранее спасибо!>
Подробнее здесь: [url]https://stackoverflow.com/questions/79763824/changing-a-variable-to-a-property-produces-an-error[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия