Ludeon Forums

RimWorld => Mods => Help => Topic started by: Katavrik on December 31, 2014, 10:46:29 AM

Title: Large projectiles
Post by: Katavrik on December 31, 2014, 10:46:29 AM
How can i make a projectile, that has a large image? A projectile that has a size of a building?

I am trying to make a mod, where large objects (like ancient ship part) fall from the sky. For that purpose i use mortar projectile and its code. Everithing works fine, but i cant make the projectile larger than 1x1. When i change the graphics of the projectile (used standard graphics for ship structural beam), it appear shrinked to the size of mortar shell. When i add <size> to the ThingDef, the game crashed at the time, that projectile should appear.

Is there a simple method to solve this? Without rewriting projectile draw code. Because, there is no example of it.
Title: Re: Large projectiles
Post by: mrofa on December 31, 2014, 11:02:41 AM
You need to rewrite object draw to make them bigger, but this is not that hard
  public override void Draw()
        {


            Matrix4x4 matrix = default(Matrix4x4);
            Vector3 s = new Vector3(num, 1f, num);
            matrix.SetTRS(DrawPos + Altitudes.AltIncVect, ExactRotation, s);
            Graphics.DrawMesh(MeshPool.plane10, matrix, CurBulletRad, 0);
        }


Thats generally how i did my projectiles grow in radiation gun.
To change the size if you look at Vector3 s = new Vector3(num, 1f, num);
vector 3 uses x,y,z coordinates, since rimworld is 2d, y coordinate is always 1f, but as you can see my x and z uses num variable to change it size, and it works generally the same like the <size>
in xml. So having Vector3(1f,1f,1f) means that object will have 1x1 size.
Title: Re: Large projectiles
Post by: Katavrik on December 31, 2014, 11:33:11 AM
Thats what i fear. I dont really understand code, i just copy paste from examples and change it. So, i copy your example and get errors: MeshPool, CurBullerRad does not exist in current context.
Should i replace it with something?

here my test code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using RimWorld;
using Verse;

namespace CrushPod
{
public class Projectile_CrushPart : Projectile_Explosive
{
public override void Draw()
{
Matrix4x4 matrix = default(Matrix4x4);
Vector3 s = new Vector3(1f, 1f, 5f);
matrix.SetTRS(DrawPos + Altitudes.AltIncVect, ExactRotation, s);
Graphics.DrawMesh(MeshPool.plane10, matrix, CurBulletRad, 0);
}

protected override void Impact(Thing hitThing)
{
Explode();
}

protected override void Explode()
{
Destroy();

BodyPartDamageInfo part = new BodyPartDamageInfo(null, BodyPartDepth.Outside);
ExplosionInfo e = new ExplosionInfo();
e.center = Position;
e.radius = def.projectile.explosionRadius;
e.dinfo = new DamageInfo( def.projectile.damageDef, 999, launcher, part );
e.preExplosionSpawnThingDef = def.projectile.preExplosionSpawnThingDef;
e.postExplosionSpawnThingDef = def.projectile.postExplosionSpawnThingDef;
e.explosionSpawnChance = def.projectile.explosionSpawnChance;
e.explosionSound = def.projectile.soundExplode;
e.projectile = def;
e.Explode();

Faction fac = Faction.OfColony;
Pawn refugee = PawnGenerator.GeneratePawn( PawnKindDef.Named("Colonist"), fac );
GenPlace.TryPlaceThing( refugee, Position, ThingPlaceMode.Near );
BodyPartDamageInfo part2 = new BodyPartDamageInfo(null, null);
DamageInfo dinfo2 = new DamageInfo( DamageTypeDefOf.Stun,10,launcher,part2);
refugee.TakeDamage(dinfo2);
}
}
}


Maybe i forget to add using of something.
Title: Re: Large projectiles
Post by: mrofa on December 31, 2014, 11:37:37 AM
Sorry Curbullet is a variable for texture ;p

try this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
using Verse.AI;
using Verse.Sound;
using RimWorld;
using VerseBase;
using RimWorld.SquadAI;

namespace MyModnamespace
{
    class MyBulletClass :Bullet
    {
        public override void Draw()
        {


            Matrix4x4 matrix = default(Matrix4x4);
            Vector3 s = new Vector3(1f, 1f, 1f);
            matrix.SetTRS(DrawPos + Altitudes.AltIncVect, ExactRotation, s);
            Graphics.DrawMesh(MeshPool.plane10, matrix, this.Graphic.MatAt(this.Rotation, null), 0);
        }

    }
}


And use Bullet insted of projectile_explosive, since this will give you acces to both projectile and projectile_explosive class
Title: Re: Large projectiles
Post by: Katavrik on December 31, 2014, 11:50:25 AM
Yes it works! Thank you for fast reply.