Initial ARPG Port
ARPG scene assets from old project are now correctly visualizing sectors generated by ZoneGenerator and updated by GameContext
This commit is contained in:
parent
1e2b474fc1
commit
d12d7c5c45
379 changed files with 42700 additions and 7253 deletions
45
Assets/Scripts/Sector Display/SnapToGrid.cs
Normal file
45
Assets/Scripts/Sector Display/SnapToGrid.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SnapToGrid : MonoBehaviour
|
||||
{
|
||||
public bool SnapPosition = false;
|
||||
public bool SnapRotation = false;
|
||||
public bool ApplyForces = false;
|
||||
|
||||
// public float RotationDamping = .5f;
|
||||
// public float PositionDamping = .1f;
|
||||
public float ForceScale = 1;
|
||||
public float Offset = 0;
|
||||
public float NormalMultiplier = 100;
|
||||
public float GravityGradientStep = .01f;
|
||||
|
||||
private Rigidbody _body;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
_body = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void LateUpdate () {
|
||||
var pos = new Vector2(transform.position.x,transform.position.z);
|
||||
|
||||
if(SnapPosition)
|
||||
transform.position = new Vector3(pos.x, Gravity.GetHeight(pos) + Offset,pos.y);
|
||||
if (SnapRotation)
|
||||
{
|
||||
var normal = Gravity.GetNormal(pos, GravityGradientStep, NormalMultiplier);
|
||||
var forward = Vector3.Cross(transform.right, normal);
|
||||
transform.rotation = Quaternion.LookRotation(forward, normal);
|
||||
}
|
||||
|
||||
if (ApplyForces)
|
||||
{
|
||||
//var currentVelocity = _body.velocity;
|
||||
var force = Gravity.GetForce(pos) * ForceScale;
|
||||
_body.AddForce(force.x,0,force.y,ForceMode.Acceleration);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue