# 2D Sprite Artwork
## Create the Horse 2D as layers in Photoshop
## Import the .PSB file in Unity
## Create the joint rig in the Sprite Editor
## Creating the hierarchy for the Horse
### Set up the Physics2D layers:
![[Pasted image 20260430104425.png]]
# Input
## Set up the Input Manager Axes
![[Pasted image 20260430104526.png]]
Jump (default settings)
![[Pasted image 20260430104638.png]]
Verticals (currently unused)
![[Pasted image 20260430104611.png]]
Setting up the Ground Detector
Horse Hierarchy
![[Pasted image 20260430085955.png]]
This is the top (MSR - MoveScaleRotate) node in the hierarchy that moves everything. Attached to it is the BodyPhysics2D script than controls the RigidBody2D.
**BodyPhysics2D.cs**
``` csharp
using Unity.VisualScripting;
using UnityEngine;
public class BodyPhysics2D : MonoBehaviour
{
public Rigidbody2D rb2d;
public Vector3 bodyDirection;
public float boost = 0f; // modified by fermented apples
public float boostDecreaseRate = 3f;
public float divisor = 0.25f;
public bool isFacingLeft = true;
public string AxisJump = "Jump";
public bool isGrounded = false;
// Animation
public Animator anim;
private void Start()
{
isGrounded = false;
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown(AxisJump))
{
anim.SetBool("isJumping", true);
Vector3 direction = rb2d.transform.up;
isGrounded = false;
}
decreaseBoost();
}
public void OnTriggerEnter2D(Collider2D collision)
{
if (collision.transform.CompareTag("Ground"))
{
anim.SetBool("isJumping", false);
isGrounded = true;
}
}
public void OnTriggerExit2D(Collider2D collision)
{
if (collision.transform.CompareTag("Ground"))
{
isGrounded = false;
}
}
public void OnTriggerStay2D(Collider2D collision)
{
if (collision.transform.CompareTag("Ground"))
{
isGrounded = true;
anim.SetBool("isJumping", false);
}
}
// boost speed based on eating fermented apples
public void modifyBoost(float amount)
{
boost += amount;
}
// set a timer to reduce the effect of a fermented apple
// decreae boost until it reaches zero
public void decreaseBoost()
{
boost *= boostDecreaseRate;
if (boost <= 1) boost = 0;
}
public void modifyBodyRB2D(Vector3 direction)
{
if (isGrounded)
{
int sign = isFacingLeft ? 1 : -1;
bodyDirection = new Vector3 ((direction.x + (boost * Mathf.Sign(direction.x)) * sign), direction.y, direction.z);
bodyDirection *= divisor;
rb2d.AddForce(bodyDirection);
//rb2d.MovePosition(rb2d.position + bodyDirection * Time.fixedDeltaTime);
}
}
public void muteBodyRB2D(Vector3 position)
{
rb2d.linearVelocity = Vector3.zero;
//int sign = isFacingLeft ? 1 : -1;
//bodyDirection = new Vector3((position.x * -sign), position.y, position.z);
//bodyDirection *= divisor;
//rb2d.AddForce(bodyDirection);
}
}
```
Horse Rig node
![[Pasted image 20260430090110.png]]
This holds a small script **jumpAnim.cs** that plays the Jump animation from the Animator connected to it.
**jumpAnim.cs**
``` csharp
using UnityEngine;
public class jumpAnim : MonoBehaviour
{
public BodyPhysics2D bodyPhysicsScript;
// physics
public Rigidbody2D rb2d;
public float jumpForce = 300f;
public void jumpAnimate()
{
Vector3 direction = rb2d.transform.up;
rb2d.AddForce(direction * (jumpForce + bodyPhysicsScript.boost));
}
}
```
Each Foot controller is an empty node with its pivot at the top of the hoof, and it includes the Targets for the Limb and the Hoof.
![[Pasted image 20260430090148.png]]
Each foot has a separate controller to manage its Input and movement
**FootPhysics2D**
``` csharp
using UnityEngine;
using static UnityEditor.Searcher.SearcherWindow.Alignment;
public class FootPhysics2D : MonoBehaviour
{
// Input
public string AxisName;
// physics2D
// public Rigidbody2D rb2d;
public Vector3 direction;
public float force = 300f;
public BodyPhysics2D BodyPhysics2DScript;
// animation
public Animator anim;
// direction
[SerializeField]
private bool isFacingLeft = false;
[SerializeField]
private int sign;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
setDirection();
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown(AxisName))
{
setDirection();
// Ipunt
float axis = Input.GetAxisRaw(AxisName);
// animation
anim.SetFloat("animSpeed", axis * sign);
anim.SetTrigger("step");
//Physics
direction = Vector3.right * force * axis;
BodyPhysics2DScript.modifyBodyRB2D(direction);
}
if (Input.GetButtonUp(AxisName))
{
// rb2d.linearVelocity = Vector3.zero;
BodyPhysics2DScript.muteBodyRB2D(direction);
}
}
public void setDirection()
{
isFacingLeft = BodyPhysics2DScript.isFacingLeft;
// for backwards step Animation Speed -1/1
sign = isFacingLeft ? -1 : 1;
}
}
```
The fermented Apple holds a Rigidbody2D set to kinematic, a Circle Collider 2D set to be a trigger and the appleCollide script that talks to the BodyPhysic2D script to give it a boost.
![[Pasted image 20260430105207.png]]
**appleCollide**
```csharp
using UnityEngine;
public class appleCollide : MonoBehaviour
{
public BodyPhysics2D bodyPhysicsScript;
public float effect = 300f;
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
bodyPhysicsScript = collision.gameObject.GetComponent<BodyPhysics2D>();
bodyPhysicsScript.modifyBoost(effect);
Debug.Log("you're fermented.");
}
}
}
```