-
Notifications
You must be signed in to change notification settings - Fork 117
Description
Combine(base+yggdrasil)
// Cobra-Mutator-SpacePirate.js
// Unreal.js / Puerts compatible
// Inspired by RA2/Yuri genetic mutator + your body rescale drawings
"use strict";
const UE = require('ue');
class CobraMutatorComponent extends UE.ActorComponent {
constructor() {
super();
// ===== MUTATION LEVELS (Yuri Style) =====
this.MutationLevel = 0; // 0 = human, 1 = buff, 2 = monster, 3 = titan
this.MaxMutationLevel = 3;
// ===== BODY RESCALE =====
this.ScaleBase = 1.0; // original size
this.ScaleBuff = 1.35; // mutation stage 1
this.ScaleMonster = 1.75; // mutation stage 2
this.ScaleTitan = 2.25; // mutation stage 3
// ===== COBRA EXTEND REACH =====
this.CobraReach = 0.0; // 0..1 (how far arms extend)
this.CobraMax = 1.0;
// ===== SPACE PIRATE BALANCE =====
this.BalanceStrength = 350.0; // physics torque keeping upright
this.PirateSway = true;
// ===== STAT BUFFS (Yuri mutator style) =====
this.HealthMultiplier = 1.0;
this.StrengthMultiplier = 1.0;
this.SpeedMultiplier = 1.0;
// Internal
this._owner = null;
this._root = null;
this._skel = null;
}
ReceiveBeginPlay() {
this._owner = this.GetOwner();
if (!this._owner) return;
this._owner.Tags.Add("SpacePirate");
this._root = this._owner.GetRootComponent();
this._skel = this._owner.FindComponentByClass(
UE.SkeletalMeshComponent.StaticClass()
);
// apply initial sizing
this._applyScaleFromMutation();
}
// ============================================================
// PUBLIC: Trigger genetic mutation (like RA2 / Yuri Mutator)
// ============================================================
MutateNextStage() {
if (this.MutationLevel < this.MaxMutationLevel) {
this.MutationLevel++;
this._applyMutationStats();
this._applyScaleFromMutation();
}
}
MutateToLevel(L) {
this.MutationLevel = Math.min(Math.max(L,0), this.MaxMutationLevel);
this._applyMutationStats();
this._applyScaleFromMutation();
}
// ============================================================
// APPLY BODY SCALE BASED ON MUTATION STAGE
// ============================================================
_applyScaleFromMutation() {
if (!this._owner) return;
let scale = this.ScaleBase;
switch(this.MutationLevel) {
case 1: scale = this.ScaleBuff; break;
case 2: scale = this.ScaleMonster; break;
case 3: scale = this.ScaleTitan; break;
}
this._owner.SetActorScale3D(new UE.Vector(scale, scale, scale));
}
// ============================================================
// APPLY MUTATION STATS (Yuri Mutator style)
// ============================================================
_applyMutationStats() {
switch(this.MutationLevel) {
case 0: // human
this.HealthMultiplier = 1.0;
this.StrengthMultiplier = 1.0;
this.SpeedMultiplier = 1.0;
break;
case 1: // buff soldier
this.HealthMultiplier = 1.5;
this.StrengthMultiplier = 1.6;
this.SpeedMultiplier = 1.1;
break;
case 2: // monster
this.HealthMultiplier = 2.2;
this.StrengthMultiplier = 2.5;
this.SpeedMultiplier = 1.0;
break;
case 3: // titan (like your drawing)
this.HealthMultiplier = 4.0;
this.StrengthMultiplier = 5.0;
this.SpeedMultiplier = 0.9;
break;
}
}
// ============================================================
// MAIN TICK: Cobra reach + balance + pirate sway
// ============================================================
ReceiveTick(DeltaSeconds) {
if (!this._owner) return;
// Cobra reach (0..1 → extend torso lean-forward)
this._applyCobraReach(DeltaSeconds);
// Stabilize upright with torque
this._applyBalance(DeltaSeconds);
// Optional sway for “space pirate walking”
if (this.PirateSway)
this._applyPirateSway(DeltaSeconds);
}
// ============================================================
// COBRA EXTENSION (like your extended arms / front lean)
// ============================================================
_applyCobraReach(dt) {
if (!this._owner) return;
const F = this.CobraReach * 25.0;
const forward = this._owner.GetActorForwardVector();
const pos = this._owner.GetActorLocation();
this._owner.SetActorLocation(
pos.add(forward.multiply(F * dt))
);
}
// ============================================================
// BALANCE — torque correction (standing upright)
// ============================================================
_applyBalance(dt) {
if (!this._root || !this._root.IsSimulatingPhysics) return;
const tr = this._root.GetComponentTransform();
const up = tr.GetUnitAxis(UE.EAxis.EAxisZ);
const worldUp = new UE.Vector(0,0,1);
const error = UE.Vector.Cross(up, worldUp);
const torque = error.MultiplyScalar(this.BalanceStrength * dt * 10.0);
this._root.AddTorqueInRadians(torque, UE.Name("None"), true);
}
// ============================================================
// PIRATE SWAY (cosmetic)
// ============================================================
_applyPirateSway(dt) {
if (!this._owner) return;
const t = UE.World.GetTimeSeconds();
const rot = this._owner.GetActorRotation();
rot.Roll += Math.sin(t * 2.2) * (this.CobraReach * 3.5);
rot.Yaw += Math.cos(t * 1.6) * (this.CobraReach * 2.0);
this._owner.SetActorRotation(rot);
}
}
module.exports = CobraMutatorComponent;
Sent from my iPhone
// CobraBalanceComponent.js
// Requires puerts (or Unreal.js) environment
// Attach this script as an Actor Component to a Pawn/Actor
"use strict";
const UE = require('ue');
class CobraBalanceComponent extends UE.ActorComponent {
constructor() {
super();
// Tunables (exposed)
this.ScaleMultiplier = 1.0; // "scale"
this.ExtendReach = 0.5; // how far the limbs reach (0..1)
this.BalanceStrength = 200.0; // how strongly the component resists tipping
this.CobraBlend = 0.0; // pose blend (0..1)
this.SpacePirateTag = "SpacePirate"; // cosmetic/faction tag
// internal
this._owner = null;
this._rootPrimitive = null;
}
ReceiveBeginPlay() {
this._owner = this.GetOwner();
if (!this._owner) return;
// set tag for visuals or logic
this._owner.Tags.Add(this.SpacePirateTag);
// find a root primitive (Physics) to apply forces; fallback to root component
const root = this._owner.GetRootComponent();
if (root && root.IsA(UE.StaticMeshComponent) || root.IsA(UE.SkeletalMeshComponent)) {
this._rootPrimitive = root;
// ensure physics is enabled only if needed
if (this._rootPrimitive.SetSimulatePhysics) {
// optional: only enable if you want lateral stabilization via forces
// this._rootPrimitive.SetSimulatePhysics(true);
}
}
// apply initial scale
this.ApplyScale(this.ScaleMultiplier);
}
// Exposed function to change scale on the fly
ApplyScale(mult) {
if (!this._owner) return;
this.ScaleMultiplier = mult;
const rootComp = this._owner.GetRootComponent();
if (rootComp) {
const v = new UE.Vector(mult, mult, mult);
rootComp.SetWorldScale3D(v);
}
}
// Called each frame
ReceiveTick(DeltaSeconds) {
if (!this._owner) return;
// 1) Balance stabilization (simple PD towards upright)
this._applyBalance(DeltaSeconds);
// 2) Apply "extend reach" as a small forward offset to a "hand" bone or socket if skeletal
this._applyExtendReach();
// 3) Drive "Cobra" pose blend (via AnimInstance parameter) if skeletal
this._driveCobraBlend();
// 4) small cosmetic "space pirate" jitter / sway when high ExtendReach
this._applySpacePirateSway(DeltaSeconds);
}
_applyBalance(DeltaSeconds) {
if (!this._rootPrimitive || !this._rootPrimitive.IsSimulatingPhysics) return;
// get current up vector and compare to world up
const transform = this._rootPrimitive.GetComponentTransform();
const up = transform.GetUnitAxis(UE.EAxis.EAxisZ); // local up
const worldUp = new UE.Vector(0, 0, 1);
// cross-product gives axis to torque
const error = UE.Vector.Cross(up, worldUp);
// proportional controller
const torque = error.MultiplyScalar(this.BalanceStrength * DeltaSeconds * 10.0);
// apply torque in world space
this._rootPrimitive.AddTorqueInRadians(torque, UE.Name("None"), true);
}
_applyExtendReach() {
if (!this._owner) return;
// If skeletal root, push a socket/bone forward proportionally
const skel = this._owner.FindComponentByClass(UE.SkeletalMeshComponent.StaticClass());
if (!skel) return;
const leftHandSocket = "hand_l_socket";
const rightHandSocket = "hand_r_socket";
// compute small local offset along forward
const forward = this._owner.GetActorForwardVector();
const offset = forward.MultiplyScalar(30.0 * this.ExtendReach); // units
// try move sockets (many projects use IK instead — this is a simple visual nudge)
// We can't move sockets at runtime easily so we nudge bone transforms (Danger: depends on rig)
if (skel.SetBoneRotationByName) {
// pseudo: blend a small additive rotation/translation
// safe fallback: create transient local offset to the mesh's relative transform
const loc = skel.RelativeLocation.Add(offset);
skel.SetRelativeLocation(loc);
}
}
_driveCobraBlend() {
if (!this._owner) return;
const skel = this._owner.FindComponentByClass(UE.SkeletalMeshComponent.StaticClass());
if (!skel) return;
const animInst = skel.GetAnimInstance();
if (!animInst) return;
// Assumes the animation blueprint has a float parameter named "CobraBlend"
if (animInst.SetMorphTarget) {
// some projects use morph targets; otherwise use anim instance set float
// try AnimInstance SetCurveValue/SetFloatParameter variant
if (animInst.SetFloatParameter) {
animInst.SetFloatParameter("CobraBlend", this.CobraBlend);
} else {
// fallback if custom binding exists
try {
animInst["CobraBlend"] = this.CobraBlend;
} catch (e) {
// ignore
}
}
}
}
_applySpacePirateSway(DeltaSeconds) {
if (!this._owner) return;
// cosmetic periodic sway when reach high
if (this.ExtendReach > 0.75) {
const t = UE.World.GetTimeSeconds();
const sway = Math.sin(t * 2.0) * (0.5 * (this.ExtendReach - 0.75));
const rot = this._owner.GetActorRotation();
rot.Pitch += sway * DeltaSeconds * 20.0;
this._owner.SetActorRotation(rot, false);
}
}
}
module.exports = CobraBalanceComponent;
unity_create_cobra.py
Run inside Unity Editor (Python for Unity package)
import os
from UnityEngine import GameObject, Vector3
from UnityEditor import AssetDatabase, PrefabUtility, EditorUtility
path config
scripts_dir = "Assets/Scripts"
prefab_dir = "Assets/Prefabs"
os.makedirs(scripts_dir, exist_ok=True)
os.makedirs(prefab_dir, exist_ok=True)
1) write C# MonoBehaviour
csharp_code = r'''
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(Animator))]
public class CobraBalance : MonoBehaviour
{
[Header("Cobra Balance Settings")]
public float scaleMultiplier = 1.0f;
[Range(0f,1f)] public float extendReach = 0.5f;
public float balanceStrength = 50f;
[Range(0f,1f)] public float cobraBlend = 0f;
public string factionTag = "SpacePirate";
Rigidbody rb;
Animator animator;
Vector3 initialScale;
void Awake() {
rb = GetComponent<Rigidbody>();
animator = GetComponent<Animator>();
initialScale = transform.localScale;
ApplyScale(scaleMultiplier);
if (!string.IsNullOrEmpty(factionTag)) {
gameObject.tag = factionTag; // must exist in tags list or error in editor
}
}
void Update() {
// Example: simple blend to animator float
if (animator) {
animator.SetFloat("CobraBlend", cobraBlend);
}
// extend reach: small forward offset to hips (could be IK)
// This example nudges transform position slightly (cosmetic)
var forward = transform.forward * extendReach * 0.05f;
transform.localPosition = Vector3.Lerp(transform.localPosition, forward, Time.deltaTime * 2f);
}
void FixedUpdate() {
// Simple upright stabilization: apply torque to align up vector with world up
if (rb == null) return;
Vector3 localUp = transform.up;
Vector3 worldUp = Vector3.up;
Vector3 error = Vector3.Cross(localUp, worldUp);
// proportional torque
rb.AddTorque(error * balanceStrength, ForceMode.Acceleration);
}
public void ApplyScale(float mult) {
scaleMultiplier = mult;
transform.localScale = initialScale * mult;
}
}
'''
cs_path = os.path.join(scripts_dir, "CobraBalance.cs")
with open(cs_path, "w", encoding="utf8") as f:
f.write(csharp_code)
AssetDatabase.ImportAsset(cs_path) # ensure Unity imports the new script
2) Create a prefab GameObject and attach components
go = GameObject("CobraSpacePirate")
default scale
go.transform.localScale = Vector3(1,1,1)
Add components (Rigidbody & Animator and the new script)
rb = go.AddComponent("Rigidbody")
anim = go.AddComponent("Animator")
Wait a little? not needed in Python, but Save as prefab
prefab_path = os.path.join(prefab_dir, "CobraSpacePirate.prefab")
prefab_obj = PrefabUtility.SaveAsPrefabAsset(go, prefab_path)
AssetDatabase.SaveAssets()
AssetDatabase.Refresh()
cleanup the temporary GO in scene
GameObject.DestroyImmediate(go)
print("Created C# script at:", cs_path)
print("Created prefab at:", prefab_path)
EditorUtility.DisplayDialog("CobraBalance", "Created CobraBalance.cs and prefab:\n" + prefab_path, "OK")
yggdrasil gene mod
import random
import time
class DNA:
def __init__(self, sequence):
self.sequence = sequence
self.genes = [random.uniform(0.0, 1.0) for _ in range(len(sequence))] # Initialize genes with random values
def mutate(self):
# Randomly mutate a gene in the sequence
mutation_site = random.randint(0, len(self.sequence) - 1)
self.sequence[mutation_site] = random.choice(['A', 'T', 'C', 'G'])
self.genes[mutation_site] = random.uniform(0.0, 1.0) # Mutate the corresponding gene value
print(f"Mutated gene at position {mutation_site}. New sequence: {self.sequence}")
def display(self):
# Display the DNA sequence
print("DNA Sequence:", ''.join(self.sequence))
def combine(self, partner_dna):
# Combine DNA with another entity
for i in range(len(self.genes)):
if random.random() < 0.5:
self.genes[i] = partner_dna.genes[i]
print(f"Combined DNA with another entity. New genes: {self.genes}")
class Yggdrasil:
def __init__(self, magical_properties):
self.magical_properties = magical_properties
def enhance(self, dna):
# Enhance the DNA with Yggdrasil's magical properties
dna.sequence.extend(self.magical_properties)
print(f"Enhanced DNA with Yggdrasil's properties: {self.magical_properties}")
dna.display()
class QuantumConstruct:
def entangle(self, dna1, dna2):
# Quantum entangle two DNA sequences
entangled_sequence = []
entangled_genes = []
for gene1, gene2 in zip(dna1.sequence, dna2.sequence):
entangled_sequence.append(gene1 if random.random() > 0.5 else gene2)
for gene1, gene2 in zip(dna1.genes, dna2.genes):
entangled_genes.append(gene1 if random.random() > 0.5 else gene2)
entangled_dna = DNA(entangled_sequence)
entangled_dna.genes = entangled_genes
print(f"Quantum entanglement result: {entangled_sequence}")
return entangled_dna
class HealthComponent:
def __init__(self, max_health):
self.max_health = max_health
self.current_health = max_health // 2 # Start at half health
def regenerate(self, rate):
while self.current_health < self.max_health:
self.current_health += rate
self.current_health = min(self.current_health, self.max_health) # Cap health at max_health
print(f"Current Health: {self.current_health}/{self.max_health}")
time.sleep(1) # Simulate time passing
class YggdrasilInteraction:
def interact(self, health_component):
health_component.current_health = health_component.max_health
print(f"Interacted with Yggdrasil. Health fully restored to {health_component.max_health}")
Main program
if name == 'main':
# Create a human DNA sequence
human_dna = DNA(['A', 'T', 'C', 'G'] * 5)
human_dna.display()
# Create a Yggdrasil plant with magical properties
yggdrasil = Yggdrasil(['E', 'T', 'R', 'N', 'L'])
# Enhance human DNA with Yggdrasil properties
yggdrasil.enhance(human_dna)
# Create a Quantum Construct
quantum_construct = QuantumConstruct()
# Entangle the enhanced human DNA with another human DNA
another_human_dna = DNA(['G', 'C', 'A', 'T'] * 5)
entangled_dna = quantum_construct.entangle(human_dna, another_human_dna)
entangled_dna.display()
# Initialize health component
health_component = HealthComponent(max_health=100)
print(f"Initial Health: {health_component.current_health}/{health_component.max_health}")
# Simulate health regeneration
health_component.regenerate(rate=5)
# Interact with Yggdrasil for instant health restoration
yggdrasil_interaction = YggdrasilInteraction()
yggdrasil_interaction.interact(health_component)
code dna
Hypothetical Script for Yggdrasil-Human DNA Integration
Disclaimer: This script is for creative and educational purposes only.
import random
Define a class to represent the DNA sequence
class DNA:
def __init__(self, sequence):
self.sequence = sequence
def mutate(self):
# Randomly mutate a gene in the sequence
mutation_site = random.randint(0, len(self.sequence) - 1)
self.sequence[mutation_site] = random.choice(['A', 'T', 'C', 'G'])
def display(self):
# Display the DNA sequence
print(''.join(self.sequence))
Define a class to represent the Yggdrasil plant
class Yggdrasil:
def __init__(self, magical_properties):
self.magical_properties = magical_properties
def enhance(self, dna):
# Enhance the DNA with Yggdrasil's magical properties
for property in self.magical_properties:
dna.sequence.append(property)
Define a class to represent the Quantum Construct
class QuantumConstruct:
def entangle(self, dna1, dna2):
# Quantum entangle two DNA sequences
entangled_sequence = []
for gene1, gene2 in zip(dna1.sequence, dna2.sequence):
entangled_sequence.append(gene1 if random.random() > 0.5 else gene2)
return DNA(entangled_sequence)
Main program
if name == 'main':
# Create a human DNA sequence
human_dna = DNA(['A', 'T', 'C', 'G'] * 5)
# Create a Yggdrasil plant with magical properties
yggdrasil = Yggdrasil(['E', 'T', 'R', 'N', 'L'])
# Enhance human DNA with Yggdrasil properties
yggdrasil.enhance(human_dna)
# Create a Quantum Construct
quantum_construct = QuantumConstruct()
# Entangle the enhanced human DNA with another human DNA
another_human_dna = DNA(['G', 'C', 'A', 'T'] * 5)
entangled_dna = quantum_construct.entangle(human_dna, another_human_dna)
# Display the entangled DNA sequence
entangled_dna.display()
@echo off
setlocal EnableDelayedExpansion
set /a "geneCount=10"
set "dna="
for /l %%i in (1,1,%geneCount%) do (
set /a "gene=!random! %% 100"
set "dna=!dna!!gene! "
)
echo DNA Sequence: !dna!
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "DNA.generated.h"
UCLASS()
class YOURGAME_API ADNA : public AActor
{
GENERATED_BODY()
public:
TArray<float> Genes;
ADNA()
{
// Initialize DNA with random values
for (int32 i = 0; i < 10; i++) // Assuming we have 10 genes
{
Genes.Add(FMath::RandRange(0.f, 1.f));
}
}
// Combine DNA with another entity
void Combine(ADNA* PartnerDNA)
{
for (int32 i = 0; i < Genes.Num(); i++)
{
// Simple crossover logic
Genes[i] = FMath::RandRange(0, 10) < 5 ? Genes[i] : PartnerDNA->Genes[i];
}
}
// Mutate the DNA
void Mutate()
{
Genes[FMath::RandRange(0, Genes.Num())] = FMath::RandRange(0.f, 1.f);
}
};
using UnityEngine;
using System.Collections.Generic;
public class DNA : MonoBehaviour
{
public List<float> genes = new List<float>();
void Start()
{
// Initialize DNA with random values
for (int i = 0; i < 10; i++) // Assuming we have 10 genes
{
genes.Add(Random.Range(0f, 1f));
}
}
// A method to combine DNA with another entity
public void Combine(DNA partnerDNA)
{
for (int i = 0; i < genes.Count; i++)
{
// Simple crossover logic
genes[i] = Random.Range(0, 10) < 5 ? genes[i] : partnerDNA.genes[i];
}
}
// A method to mutate the DNA
public void Mutate()
{
genes[Random.Range(0, genes.Count)] = Random.Range(0f, 1f);
}
}
@echo off
setlocal EnableDelayedExpansion
set /a "maxHealth=100"
set /a "currentHealth=50"
set /a "yggdrasilPower=1"
echo You have encountered the Yggdrasil plant.
echo Press any key to interact with the plant and restore your health.
pause >nul
set /a "currentHealth=maxHealth"
echo Your health has been restored to !maxHealth! by the power of Yggdrasil.
#include "GameFramework/Actor.h"
class AYggdrasilInteractionActor : public AActor
{
public:
UPROPERTY(EditAnywhere)
AActor* YggdrasilPlant;
virtual void NotifyActorBeginOverlap(AActor* OtherActor) override
{
if (OtherActor == YggdrasilPlant)
{
// Interaction logic goes here
UHealthComponent* HealthComp = FindComponentByClass<UHealthComponent>();
HealthComp->CurrentHealth = HealthComp->MaxHealth;
// Add any additional effects
}
}
};
using UnityEngine;
public class YggdrasilInteraction : MonoBehaviour
{
public GameObject yggdrasilPlant;
void OnTriggerEnter(Collider other)
{
if (other.gameObject == yggdrasilPlant)
{
// Implement the interaction logic here
// For example, regenerate health or gain a power-up
GetComponent<HealthComponent>().currentHealth = GetComponent<HealthComponent>().maxHealth;
// Add any other effects of interacting with Yggdrasil
}
}
}
@echo off
setlocal EnableDelayedExpansion
set /a "maxHealth=100"
set /a "currentHealth=50"
set /a "regenerationRate=1"
:regenerate
if %currentHealth% lss %maxHealth% (
set /a "currentHealth+=regenerationRate"
echo Current Health: !currentHealth!
timeout /t 1 >nul
goto regenerate
)
#include "GameFramework/Actor.h"
class AEternalImmortalRegenerationActor : public AActor
{
public:
float RegenerationRate = 5.0f; // Health per second
virtual void Tick(float DeltaSeconds) override
{
Super::Tick(DeltaSeconds);
UHealthComponent* HealthComp = FindComponentByClass<UHealthComponent>();
if (HealthComp->CurrentHealth < HealthComp->MaxHealth)
{
HealthComp->CurrentHealth += RegenerationRate * DeltaSeconds;
}
}
};
using UnityEngine;
public class EternalImmortalRegeneration : MonoBehaviour
{
public float regenerationRate = 5f; // Health per second
void Update()
{
if (GetComponent<HealthComponent>().currentHealth < GetComponent<HealthComponent>().maxHealth)
{
GetComponent<HealthComponent>().currentHealth += regenerationRate * Time.deltaTime;
}
}
}
@echo off
setlocal EnableDelayedExpansion
set /a "maxHealth=100"
set /a "currentHealth=50"
set /a "regenerationRate=1"
:regenerate
if %currentHealth% lss %maxHealth% (
set /a "currentHealth+=regenerationRate"
echo Current Health: !currentHealth!
timeout /t 1 >nul
goto regenerate
)
#include "GameFramework/Actor.h"
class AEternalRegenerationActor : public AActor
{
public:
float RegenerationRate = 5.0f; // Health per second
virtual void Tick(float DeltaSeconds) override
{
Super::Tick(DeltaSeconds);
UHealthComponent* HealthComp = FindComponentByClass<UHealthComponent>();
if (HealthComp->CurrentHealth < HealthComp->MaxHealth)
{
HealthComp->CurrentHealth += RegenerationRate * DeltaSeconds;
}
}
};
using UnityEngine;
public class EternalRegeneration : MonoBehaviour
{
public float regenerationRate = 5f; // Health per second
void Update()
{
if (GetComponent<HealthComponent>().currentHealth < GetComponent<HealthComponent>().maxHealth)
{
GetComponent<HealthComponent>().currentHealth += regenerationRate * Time.deltaTime;
}
}
}
// Cobra-Mutator-SpacePirate.js
// Unreal.js / Puerts compatible
// Inspired by RA2/Yuri genetic mutator + your body rescale drawings
"use strict";
const UE = require('ue');
class CobraMutatorComponent extends UE.ActorComponent {
constructor() {
super();
// ===== MUTATION LEVELS (Yuri Style) =====
this.MutationLevel = 0; // 0 = human, 1 = buff, 2 = monster, 3 = titan
this.MaxMutationLevel = 3;
// ===== BODY RESCALE =====
this.ScaleBase = 1.0; // original size
this.ScaleBuff = 1.35; // mutation stage 1
this.ScaleMonster = 1.75; // mutation stage 2
this.ScaleTitan = 2.25; // mutation stage 3
// ===== COBRA EXTEND REACH =====
this.CobraReach = 0.0; // 0..1 (how far arms extend)
this.CobraMax = 1.0;
// ===== SPACE PIRATE BALANCE =====
this.BalanceStrength = 350.0; // physics torque keeping upright
this.PirateSway = true;
// ===== STAT BUFFS (Yuri mutator style) =====
this.HealthMultiplier = 1.0;
this.StrengthMultiplier = 1.0;
this.SpeedMultiplier = 1.0;
// Internal
this._owner = null;
this._root = null;
this._skel = null;
}
ReceiveBeginPlay() {
this._owner = this.GetOwner();
if (!this._owner) return;
this._owner.Tags.Add("SpacePirate");
this._root = this._owner.GetRootComponent();
this._skel = this._owner.FindComponentByClass(
UE.SkeletalMeshComponent.StaticClass()
);
// apply initial sizing
this._applyScaleFromMutation();
}
// ============================================================
// PUBLIC: Trigger genetic mutation (like RA2 / Yuri Mutator)
// ============================================================
MutateNextStage() {
if (this.MutationLevel < this.MaxMutationLevel) {
this.MutationLevel++;
this._applyMutationStats();
this._applyScaleFromMutation();
}
}
MutateToLevel(L) {
this.MutationLevel = Math.min(Math.max(L,0), this.MaxMutationLevel);
this._applyMutationStats();
this._applyScaleFromMutation();
}
// ============================================================
// APPLY BODY SCALE BASED ON MUTATION STAGE
// ============================================================
_applyScaleFromMutation() {
if (!this._owner) return;
let scale = this.ScaleBase;
switch(this.MutationLevel) {
case 1: scale = this.ScaleBuff; break;
case 2: scale = this.ScaleMonster; break;
case 3: scale = this.ScaleTitan; break;
}
this._owner.SetActorScale3D(new UE.Vector(scale, scale, scale));
}
// ============================================================
// APPLY MUTATION STATS (Yuri Mutator style)
// ============================================================
_applyMutationStats() {
switch(this.MutationLevel) {
case 0: // human
this.HealthMultiplier = 1.0;
this.StrengthMultiplier = 1.0;
this.SpeedMultiplier = 1.0;
break;
case 1: // buff soldier
this.HealthMultiplier = 1.5;
this.StrengthMultiplier = 1.6;
this.SpeedMultiplier = 1.1;
break;
case 2: // monster
this.HealthMultiplier = 2.2;
this.StrengthMultiplier = 2.5;
this.SpeedMultiplier = 1.0;
break;
case 3: // titan (like your drawing)
this.HealthMultiplier = 4.0;
this.StrengthMultiplier = 5.0;
this.SpeedMultiplier = 0.9;
break;
}
}
// ============================================================
// MAIN TICK: Cobra reach + balance + pirate sway
// ============================================================
ReceiveTick(DeltaSeconds) {
if (!this._owner) return;
// Cobra reach (0..1 → extend torso lean-forward)
this._applyCobraReach(DeltaSeconds);
// Stabilize upright with torque
this._applyBalance(DeltaSeconds);
// Optional sway for “space pirate walking”
if (this.PirateSway)
this._applyPirateSway(DeltaSeconds);
}
// ============================================================
// COBRA EXTENSION (like your extended arms / front lean)
// ============================================================
_applyCobraReach(dt) {
if (!this._owner) return;
const F = this.CobraReach * 25.0;
const forward = this._owner.GetActorForwardVector();
const pos = this._owner.GetActorLocation();
this._owner.SetActorLocation(
pos.add(forward.multiply(F * dt))
);
}
// ============================================================
// BALANCE — torque correction (standing upright)
// ============================================================
_applyBalance(dt) {
if (!this._root || !this._root.IsSimulatingPhysics) return;
const tr = this._root.GetComponentTransform();
const up = tr.GetUnitAxis(UE.EAxis.EAxisZ);
const worldUp = new UE.Vector(0,0,1);
const error = UE.Vector.Cross(up, worldUp);
const torque = error.MultiplyScalar(this.BalanceStrength * dt * 10.0);
this._root.AddTorqueInRadians(torque, UE.Name("None"), true);
}
// ============================================================
// PIRATE SWAY (cosmetic)
// ============================================================
_applyPirateSway(dt) {
if (!this._owner) return;
const t = UE.World.GetTimeSeconds();
const rot = this._owner.GetActorRotation();
rot.Roll += Math.sin(t * 2.2) * (this.CobraReach * 3.5);
rot.Yaw += Math.cos(t * 1.6) * (this.CobraReach * 2.0);
this._owner.SetActorRotation(rot);
}
}
module.exports = CobraMutatorComponent;
Sent from my iPhone
// CobraBalanceComponent.js
// Requires puerts (or Unreal.js) environment
// Attach this script as an Actor Component to a Pawn/Actor
"use strict";
const UE = require('ue');
class CobraBalanceComponent extends UE.ActorComponent {
constructor() {
super();
// Tunables (exposed)
this.ScaleMultiplier = 1.0; // "scale"
this.ExtendReach = 0.5; // how far the limbs reach (0..1)
this.BalanceStrength = 200.0; // how strongly the component resists tipping
this.CobraBlend = 0.0; // pose blend (0..1)
this.SpacePirateTag = "SpacePirate"; // cosmetic/faction tag
// internal
this._owner = null;
this._rootPrimitive = null;
}
ReceiveBeginPlay() {
this._owner = this.GetOwner();
if (!this._owner) return;
// set tag for visuals or logic
this._owner.Tags.Add(this.SpacePirateTag);
// find a root primitive (Physics) to apply forces; fallback to root component
const root = this._owner.GetRootComponent();
if (root && root.IsA(UE.StaticMeshComponent) || root.IsA(UE.SkeletalMeshComponent)) {
this._rootPrimitive = root;
// ensure physics is enabled only if needed
if (this._rootPrimitive.SetSimulatePhysics) {
// optional: only enable if you want lateral stabilization via forces
// this._rootPrimitive.SetSimulatePhysics(true);
}
}
// apply initial scale
this.ApplyScale(this.ScaleMultiplier);
}
// Exposed function to change scale on the fly
ApplyScale(mult) {
if (!this._owner) return;
this.ScaleMultiplier = mult;
const rootComp = this._owner.GetRootComponent();
if (rootComp) {
const v = new UE.Vector(mult, mult, mult);
rootComp.SetWorldScale3D(v);
}
}
// Called each frame
ReceiveTick(DeltaSeconds) {
if (!this._owner) return;
// 1) Balance stabilization (simple PD towards upright)
this._applyBalance(DeltaSeconds);
// 2) Apply "extend reach" as a small forward offset to a "hand" bone or socket if skeletal
this._applyExtendReach();
// 3) Drive "Cobra" pose blend (via AnimInstance parameter) if skeletal
this._driveCobraBlend();
// 4) small cosmetic "space pirate" jitter / sway when high ExtendReach
this._applySpacePirateSway(DeltaSeconds);
}
_applyBalance(DeltaSeconds) {
if (!this._rootPrimitive || !this._rootPrimitive.IsSimulatingPhysics) return;
// get current up vector and compare to world up
const transform = this._rootPrimitive.GetComponentTransform();
const up = transform.GetUnitAxis(UE.EAxis.EAxisZ); // local up
const worldUp = new UE.Vector(0, 0, 1);
// cross-product gives axis to torque
const error = UE.Vector.Cross(up, worldUp);
// proportional controller
const torque = error.MultiplyScalar(this.BalanceStrength * DeltaSeconds * 10.0);
// apply torque in world space
this._rootPrimitive.AddTorqueInRadians(torque, UE.Name("None"), true);
}
_applyExtendReach() {
if (!this._owner) return;
// If skeletal root, push a socket/bone forward proportionally
const skel = this._owner.FindComponentByClass(UE.SkeletalMeshComponent.StaticClass());
if (!skel) return;
const leftHandSocket = "hand_l_socket";
const rightHandSocket = "hand_r_socket";
// compute small local offset along forward
const forward = this._owner.GetActorForwardVector();
const offset = forward.MultiplyScalar(30.0 * this.ExtendReach); // units
// try move sockets (many projects use IK instead — this is a simple visual nudge)
// We can't move sockets at runtime easily so we nudge bone transforms (Danger: depends on rig)
if (skel.SetBoneRotationByName) {
// pseudo: blend a small additive rotation/translation
// safe fallback: create transient local offset to the mesh's relative transform
const loc = skel.RelativeLocation.Add(offset);
skel.SetRelativeLocation(loc);
}
}
_driveCobraBlend() {
if (!this._owner) return;
const skel = this._owner.FindComponentByClass(UE.SkeletalMeshComponent.StaticClass());
if (!skel) return;
const animInst = skel.GetAnimInstance();
if (!animInst) return;
// Assumes the animation blueprint has a float parameter named "CobraBlend"
if (animInst.SetMorphTarget) {
// some projects use morph targets; otherwise use anim instance set float
// try AnimInstance SetCurveValue/SetFloatParameter variant
if (animInst.SetFloatParameter) {
animInst.SetFloatParameter("CobraBlend", this.CobraBlend);
} else {
// fallback if custom binding exists
try {
animInst["CobraBlend"] = this.CobraBlend;
} catch (e) {
// ignore
}
}
}
}
_applySpacePirateSway(DeltaSeconds) {
if (!this._owner) return;
// cosmetic periodic sway when reach high
if (this.ExtendReach > 0.75) {
const t = UE.World.GetTimeSeconds();
const sway = Math.sin(t * 2.0) * (0.5 * (this.ExtendReach - 0.75));
const rot = this._owner.GetActorRotation();
rot.Pitch += sway * DeltaSeconds * 20.0;
this._owner.SetActorRotation(rot, false);
}
}
}
module.exports = CobraBalanceComponent;
unity_create_cobra.py
Run inside Unity Editor (Python for Unity package)
import os
from UnityEngine import GameObject, Vector3
from UnityEditor import AssetDatabase, PrefabUtility, EditorUtility
path config
scripts_dir = "Assets/Scripts"
prefab_dir = "Assets/Prefabs"
os.makedirs(scripts_dir, exist_ok=True)
os.makedirs(prefab_dir, exist_ok=True)
1) write C# MonoBehaviour
csharp_code = r'''
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(Animator))]
public class CobraBalance : MonoBehaviour
{
[Header("Cobra Balance Settings")]
public float scaleMultiplier = 1.0f;
[Range(0f,1f)] public float extendReach = 0.5f;
public float balanceStrength = 50f;
[Range(0f,1f)] public float cobraBlend = 0f;
public string factionTag = "SpacePirate";
Rigidbody rb;
Animator animator;
Vector3 initialScale;
void Awake() {
rb = GetComponent<Rigidbody>();
animator = GetComponent<Animator>();
initialScale = transform.localScale;
ApplyScale(scaleMultiplier);
if (!string.IsNullOrEmpty(factionTag)) {
gameObject.tag = factionTag; // must exist in tags list or error in editor
}
}
void Update() {
// Example: simple blend to animator float
if (animator) {
animator.SetFloat("CobraBlend", cobraBlend);
}
// extend reach: small forward offset to hips (could be IK)
// This example nudges transform position slightly (cosmetic)
var forward = transform.forward * extendReach * 0.05f;
transform.localPosition = Vector3.Lerp(transform.localPosition, forward, Time.deltaTime * 2f);
}
void FixedUpdate() {
// Simple upright stabilization: apply torque to align up vector with world up
if (rb == null) return;
Vector3 localUp = transform.up;
Vector3 worldUp = Vector3.up;
Vector3 error = Vector3.Cross(localUp, worldUp);
// proportional torque
rb.AddTorque(error * balanceStrength, ForceMode.Acceleration);
}
public void ApplyScale(float mult) {
scaleMultiplier = mult;
transform.localScale = initialScale * mult;
}
}
'''
cs_path = os.path.join(scripts_dir, "CobraBalance.cs")
with open(cs_path, "w", encoding="utf8") as f:
f.write(csharp_code)
AssetDatabase.ImportAsset(cs_path) # ensure Unity imports the new script
2) Create a prefab GameObject and attach components
go = GameObject("CobraSpacePirate")
default scale
go.transform.localScale = Vector3(1,1,1)
Add components (Rigidbody & Animator and the new script)
rb = go.AddComponent("Rigidbody")
anim = go.AddComponent("Animator")
Wait a little? not needed in Python, but Save as prefab
prefab_path = os.path.join(prefab_dir, "CobraSpacePirate.prefab")
prefab_obj = PrefabUtility.SaveAsPrefabAsset(go, prefab_path)
AssetDatabase.SaveAssets()
AssetDatabase.Refresh()
cleanup the temporary GO in scene
GameObject.DestroyImmediate(go)
print("Created C# script at:", cs_path)
print("Created prefab at:", prefab_path)
EditorUtility.DisplayDialog("CobraBalance", "Created CobraBalance.cs and prefab:\n" + prefab_path, "OK")