Entity.Physics.Impulse not working

#1
I have a bullet entity, spawning successfully but when i use a impulse to move it, it stays put.

Code: Select all

using CryEngine.Common; using CryEngine.EntitySystem; namespace CryEngine.SampleApp { [EntityClass("Bullet", "Game", null, "User.bmp")] class Bullet : EntityComponent { private string BulletGeoURL = "Objects/Default/bullet.cgf"; public Bullet() { Initialize(); } private void Initialize() { SetEntityModel(); } public override void OnCollision(CollisionEvent collisionEvent) { //Global.gEnv.pEntitySystem.RemoveEntity(Entity.Id); } public override void OnPrePhysicsUpdate(float frameTime) { base.OnPrePhysicsUpdate(frameTime); Entity.Physics.Impulse = Entity.Rotation.Forward * 3; } private void SetEntityModel() { var entity = Entity; // Override material so that we can see the ball rolling more easily entity.LoadGeometry(0, BulletGeoURL); var physicsEntity = Entity.Physics; if (physicsEntity == null) { return; } // Physicalize the player as type Living. // This physical entity type is specifically implemented for players Entity.Physics.Physicalize(90, EPhysicalizationType.ePT_Rigid); } } }
Any help would be appreciated

Re: Entity.Physics.Impulse not working

#2
http://docs.cryengine.com/display/CEPRO ... nteraction
IPhysicalEntity phyEntity = myEntity.BaseEntity.GetPhysics();
if (phyEntity != null)
{
// Define velocity object.
var peActionSetVelocity = new pe_action_set_velocity();
peActionSetVelocity.v = new Vec3(xSpeed, ySpeed, zSpeed);
// Set velocity on entity.
phyEntity.Action(peActionSetVelocity);
Last edited by mknmknmknjk on Fri Jun 30, 2017 12:51 pm, edited 1 time in total.

Re: Entity.Physics.Impulse not working

#7
Hi, I've been working on the 3rd person template for the 5.4 release so I can already show you how I implemented the bullets in there. You can already find the template on Github by the way, but keep in mind that some C# functions are not exposed yet in 5.3. You can of course look up how those functions are implemented in the engine and see if you can get the same behaviour by adding "using CryEngine.Common;" at the top of your c# file.
Here is how I implemented the bullet with some small adjustments to make it work in 5.3. It could be that I missed some 5.4 functionality so you might need to change it a bit.

Code: Select all

namespace CryEngine.Game.Weapons { public struct BulletData { public string GeometryUrl { get; set; } public string MaterialUrl { get; set; } public float Scale { get; set; } public float Speed { get; set; } public float Mass { get; set; } } public class Bullet : EntityComponent { /// <summary> /// The lifetime of a bullet. After this amount of time has passed the bullet will be removed. /// </summary> private const float MaxLifetime = 10f; /// <summary> /// The time this bullet has been alive. If it reaches MaxLifetime this bullet will be removed. /// </summary> private float _lifetime = 0; public void Initialize(BulletData bulletData) { // Set the model Entity.LoadGeometry(0, bulletData.GeometryUrl); // Load the custom bullet material. if(!string.IsNullOrWhiteSpace(bulletData.MaterialUrl)) { Entity.LoadMaterial(bulletData.MaterialUrl); } // Now create the physical representation of the entity var physics = Entity.Physics; physics.Physicalize(bulletData.Mass, EPhysicalizationType.ePT_Rigid); // Make sure that bullets are always rendered regardless of distance // This will be added in 5.4 //Entity.SetViewDistanceRatio(1.0f); physics.Impulse = Entity.WorldRotation.Forward * bulletData.Speed; } protected override void OnUpdate(float frameTime) { base.OnUpdate(frameTime); _lifetime += frameTime; if(_lifetime > MaxLifetime) { Entity.Remove(); } } protected override void OnCollision(EntitySystem.CollisionEvent collisionEvent) { base.OnCollision(collisionEvent); //Remove the entity when it hits something. Entity.Remove(); } } }

Re: Entity.Physics.Impulse not working

#9
Hi, I've been working on the 3rd person template for the 5.4 release so I can already show you how I implemented the bullets in there. You can already find the template on Github by the way, but keep in mind that some C# functions are not exposed yet in 5.3. You can of course look up how those functions are implemented in the engine and see if you can get the same behaviour by adding "using CryEngine.Common;" at the top of your c# file.
Here is how I implemented the bullet with some small adjustments to make it work in 5.3. It could be that I missed some 5.4 functionality so you might need to change it a bit.

Code: Select all

namespace CryEngine.Game.Weapons { public struct BulletData { public string GeometryUrl { get; set; } public string MaterialUrl { get; set; } public float Scale { get; set; } public float Speed { get; set; } public float Mass { get; set; } } public class Bullet : EntityComponent { /// <summary> /// The lifetime of a bullet. After this amount of time has passed the bullet will be removed. /// </summary> private const float MaxLifetime = 10f; /// <summary> /// The time this bullet has been alive. If it reaches MaxLifetime this bullet will be removed. /// </summary> private float _lifetime = 0; public void Initialize(BulletData bulletData) { // Set the model Entity.LoadGeometry(0, bulletData.GeometryUrl); // Load the custom bullet material. if(!string.IsNullOrWhiteSpace(bulletData.MaterialUrl)) { Entity.LoadMaterial(bulletData.MaterialUrl); } // Now create the physical representation of the entity var physics = Entity.Physics; physics.Physicalize(bulletData.Mass, EPhysicalizationType.ePT_Rigid); // Make sure that bullets are always rendered regardless of distance // This will be added in 5.4 //Entity.SetViewDistanceRatio(1.0f); physics.Impulse = Entity.WorldRotation.Forward * bulletData.Speed; } protected override void OnUpdate(float frameTime) { base.OnUpdate(frameTime); _lifetime += frameTime; if(_lifetime > MaxLifetime) { Entity.Remove(); } } protected override void OnCollision(EntitySystem.CollisionEvent collisionEvent) { base.OnCollision(collisionEvent); //Remove the entity when it hits something. Entity.Remove(); } } }
That's what I started with. It didn't work. Does it matter that the bullet model is an imported .fbx file from blender?
Last edited by chazzvader on Fri Jun 30, 2017 2:44 pm, edited 1 time in total.

Re: Entity.Physics.Impulse not working

#10
A what? I'm new to this.

EDIT: I don't think so. How do I add one?
Easiest would be to use one of the primitive objects that are shipped with the engine. In the template for 5.4 it uses "Objects/Default/primitive_sphere.cgf" for the bullets for example. Once it's working with the primitive objects you can later switch them to a proper model for the bullets with a custom made proxy. You can take a look at the Rifle.cs file on github to see how it works with the bullet I've posted before.

Who is online

Users browsing this forum: No registered users and 2 guests