Search the Community
Showing results for tags 'Collision'.
-
Debug mode has no such problem but TransformPoint in same code in release mode don't returns true when it should. A model becomes yellow when it goes through a box in debug( i.e. TransformPoint() returns true). #include "UltraEngine.h" #include "Components/Mover.hpp" using namespace UltraEngine; int main(int argc, const char* argv[]) { //Get the displays auto displays = GetDisplays(); //Create a window auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); //Create a framebuffer auto framebuffer = CreateFramebuffer(window); //Create a world auto world = CreateWorld(); //Create a camera auto camera = CreateCamera(world); camera->SetClearColor(0.8); camera->Turn(35, 0, 0); camera->Move(0, 0, -2); camera->SetDebugPhysicsMode(true); //Create light auto light = CreateBoxLight(world); light->SetRange(-20, 20); light->SetArea(20, 20); light->SetRotation(35, 35, 0); auto unlitMaterial = CreateMaterial(); auto unlitShader = LoadShaderFamily("Shaders/Unlit.json"); unlitMaterial->SetShaderFamily(unlitShader); int width = 2, height = 1, length = 3; auto model = CreateModel(world); auto mesh = model->AddMesh(); mesh->AddVertex(0, 0, 0); //S mesh->AddVertex(-width * 0.5, -height * 0.5, length);//NW mesh->AddVertex(width * 0.5, -height * 0.5, length);//NE mesh->AddPrimitive(2, 1, 0);//S , NW, NE mesh->AddVertex(-width * 0.5, height * 0.5, length);//NW h mesh->AddVertex(width * 0.5, height * 0.5, length);//NE h mesh->AddPrimitive(0, 3, 4);//S , NW h, NE h mesh->AddPrimitive(0, 1, 3);//left mesh->AddPrimitive(4, 3, 1); //"face" mesh->AddPrimitive(2, 4, 1); //"face" mesh->AddPrimitive(0, 4, 2); //"right" auto& mat = unlitMaterial; mat->SetTransparent(true); model->SetMaterial(mat); model->SetColor(0.5f, 0.8f, 0, 0.25f); model->SetPosition(0, 0, 0); auto collider = CreateConvexHullCollider(mesh); model->SetCollider(collider); Vec3 targetPos(2, 0, 0); auto box = CreateBox(world, 0.1f); box->SetPosition(targetPos); auto component = model->AddComponent<Mover>(); component->rotationspeed.y = 45; //Main loop while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { auto newTargetPos = TransformPoint(targetPos, Mat4(), model->GetMatrix()); bool isInside = model->GetCollider()->IntersectsPoint(newTargetPos); if (isInside) { model->SetColor(1, 1, 0, 1); } else { model->SetColor(1, 0, 0, 1); } world->Update(); world->Render(framebuffer); } return 0; }
-
Haven't had time to put together an example yet, but here's a video of the issue and the collider I'm using is attached as well as the .obj it was generated from. This has been happening since the fix for Mesh Colliders. Before then this shape didn't work at all. The video is just a player controller getting stuck inside this collider and when it does collide, it jitters a lot. Physics.zip
-
If set collision hook to a prop, and add into it "Set collision - none" it will be get forse without collision
-
I create a collision patch for my terrain on the fly with the following code which increases the memory usage over time. Commenting out creating the shape seams to stop it. #include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } Model* box; Camera* camera; bool wireframe = false; bool App::Start() { window = Window::Create("PolyMesh",50,50, 1024, 768); window->Show(); context = Context::Create(window); world = World::Create(); DirectionalLight* light = DirectionalLight::Create(); light->SetRotation(35, 35, 35); camera = Camera::Create(); box = Model::Box(); box->Move(0, 0, 2); return true; } bool App::Loop() { if (window->KeyHit(Key::Escape) == true) { return false; } if (window->KeyHit(Key::F1) == true) { camera->GetDebugPhysicsMode() == true ? camera->SetDebugPhysicsMode(false) : camera->SetDebugPhysicsMode(true); } if (window->KeyHit(Key::F2) == true) { if (wireframe == true) { camera->SetDrawMode(0); wireframe = false; } else { camera->SetDrawMode(2); wireframe = true; } } Vec3 rot = box->GetRotation(); rot.x += 0.2f; rot.y += 0.2f; rot.z += 0.2f; box->SetRotation(rot); //Make a collsion surface on the fly for terrain/////////////////// int xGrid = 3; int zGrid = 3; int vertIndex = 0; Surface* surface = Surface::Create(); for (int z = 0; z < zGrid; z++) { for (int x = 0; x < xGrid; x++) { surface->AddVertex(x, 0.0f, z); if (z != 0 && x != 0) { surface->AddTriangle(vertIndex, vertIndex - xGrid, vertIndex - 1); surface->AddTriangle(vertIndex - xGrid, vertIndex - xGrid - 1, vertIndex - 1); } vertIndex++; } } Shape* shape = Shape::PolyMesh(surface);//memory leak here? //box->SetShape(shape); shape->Release(); surface->Release(); ////////////////////////////////////////////////////////////////////// Time::Update(); world->Update(); world->Render(); context->SetBlendMode(Blend::Alpha); context->DrawStats(10.0f, 10.0f, true); context->Sync(true); return true; }
-
Hi, I have some switches and doors (SwingingDoors) that have Use function and calls to open or light up the rooms. But now I want that when my VR controller collide with the door or the light, first detect that I can "interact" with it (atm painting a Sphere...) and when I click on controller trigger, call to "Use" function of the collided entity (door or switch). Now, I replicated the code from FPSPlayer to interact with the E Key, and is "working" but is very awful I'm trying to write what I'm doing (very very very bad) on VRPlayer function Script:UpdateWorld() local pickInfo = PickInfo() --Usable object with Trigger Button: DANI if VR:GetControllerButtonDown(VR.Right,VR.TriggerButton)==true then local p0 = controller:GetPosition(true) local p1 = Transform:Point(0,0,self.useDistance,controller,nil) if self.entity.world:Pick(p0,p1, pickInfo, self.pickradius, true) then --Looks for any entity in the hierarchy that has a "Use" function local usableentity = self:FindUsableEntity(pickInfo.entity) if usableentity~=nil then --Use the object, whatever it may be usableentity.script:Use(self) end end end self.canUse = false pickInfo = PickInfo() local p0 = controller:GetPosition() local p1 = Transform:Point(self.useDistance,self.useDistance,self.useDistance,controller,nil) if self.entity.world:Pick(p0,p1, pickInfo, self.pickradius, true) then if self:FindUsableEntity(pickInfo.entity)~=nil then self.picksphere:SetPosition(pickInfo.position); self.canUse=true else local mass = pickInfo.entity:GetMass() if mass>0 and mass<=self.maxcarryweight then self.canUse = true end end else self.picksphere:SetPosition(0,0,0) end
-
hey guys, got a high fast one thrown at me today, it involves collisions, which i have not been able to fully immerse myself into. We are learning to use leadwerks over here and we have set up a collision test. It involves a rotating box, with a "laser pointer" shooting a ray out of it. there are 3 other boxes on the floor, each sitting pretty, doing nothing. When the laser pointer spins, the laser eventually contacts the surface of the box. This causes the API to change the color of the collided-with box, to red. This is what we wanted. The second the laser touches the box, it changes color to red, but after the laser pointer is no longer in contact with the box, the box stays red. We want the box to change back to iits original color. Its as if the collision system needs to be reset? Is that the case? Standby, my co-worker will send me the code he has been working on .
-
Hi everyone, it might be a stupid question but i just startet working with Leadwerks and LUA. So i am doing the tutorial series available here -> youtube and i have the problem that the player doesn't die when he falls from a high position. Everything else from the tutorial is working but maybe i missed something at the beginning? I remember that something didn't work at the beginning regarding the "name" value of the player. In the tutorial it was just "player" but in my version the value was "FPSPlayer". So i had to rename it to "player" to make the tutorial work on LW 4.5. Perhaps that's the problem? I attached my project and it would be really helpful if someone could have a look at it or just point me into the right direction. tutorial.7z
-
Is a PolyMesh() trigger suposed to work? I set one up but every time objects fly straight through without invoking the collision hook. Using a sphere or box though works fine.
-
Hi, I have made a large sphere shape which is set up as a trigger and I have attached a collision hook to a cube which I fire from the camera at the sphere. The hook is called upon collision but also seems to be called when the cube is inside the sphere. Even if it has been created in the sphere on start-up. Is there a way to only detect a collision with a face? Not the volume as well? I thought of just removing the hook upon first collision, but I'd like it there for collisions that may happen later. Any ideas?
-
Hello. I am super new to Leadwerks, Lua script, and OOP languages in general. I am just trying to put together a simple game where the player can move a character around a room and dodge a bouncing ball-of-death; but the collisions are giving me a hard time. At this point, the script attached to my player character model simply contains the following code: Script.moveRate = 0.05 --float "Movement Rate" function Script:UpdatePhysics() if window:KeyDown(Key.W) then self.entity:Translate(0, 0, self.moveRate) end if window:KeyDown(Key.S) then self.entity:Translate(0, 0, -self.moveRate) end if window:KeyDown(Key.A) then self.entity:Translate(-self.moveRate, 0, 0) end if window:KeyDown(Key.D) then self.entity:Translate(self.moveRate, 0, 0) end end I have tried using Leadwerk's built-in physics to handle collisions, but they yield unwanted results. If the Physics Mode is set to Rigid Body, then the character model gets knocked over upon making contact with a wall brush; and if the Physics mode is set to Character Physics, the model sinks halfway into the floor brush and bounces when it collides with a wall, sometimes being launched away from the wall when the button is released. I have tried various setting combinations of Physics Mode and Physics Types, but none have yielded better results. In light of this, I thought I might try writing my own code to handle the collision behavior, but I can't seem to find any commands in the API reference that deal with collisions, aside from the CollisionHook command, which I am completely baffled by. (I have no idea what a "hook" is, and there is no example code given.) Apparently, I am missing something, somewhere. Can anyone point me in the right direction? Thanks!
-
I am trying to create a platformer game where you can run, jump and shoot projectiles (lemons like in megaman). I am using 3-D models restricted to a 2-D plane. I already have my character running and jumping, however I am having a very difficult time trying to get shooting. I am not sure how to start. Should I have the chatterer controller script generate the projectiles? Can I make a global trigger that follows the character and emit the bullets? I am not sure where/how to generate the projectiles and where/how to do collision detection. can I have it shot a .pfb that I have made, or will it have to be a basic shape, or sprite? Thanks!
- 8 replies
-
- projectile
- generation
-
(and 1 more)
Tagged with:
-
I have the Cottages package from the Workshop and try to add a Poly Mesh collider to Cottage 1 or Cottage 2. This appears to work fine: But when I run the game, the outside walls have no collision. Reopening the MDL I find that it is clear they are lacking that part of the collision mesh somehow: Is there any way I can fix this or is it just a bug?
-
So I have tried everything I dont know if its the object or what but the generetor(the base one that comes with leadwerks) cannot have collision set upon it. am I missing something?
-
I am developping a small Foosball game. I set the ball object physics to Rigid Body, Prop, and with a mass of 5. The foosmen on a rod are attached to a pivot which controls their rotation. Each foosman physics is set to Rigid Body, Scene, Nav Obstacle = true. When the ball is moving, it can react to the foosmen rotating. If the ball is stopped, the foosmen pass through the ball. I suspect the way I set the physics is responsable for this. Does someone have a suggestion on how to set physics setting correctly so the foosmen can hit the ball when they are rotating. Thanks. E.
-
Well this is my second post in a row on here. I have falling barrels set up and I want them to have collision with the player. If I turn Swept Collision on on the barrel, when it hits the player it automatically kills them. I want a collision where it will knock my player off the tiny cylinder platform, and onto the death trigger so he gets reset to the spawn point. How do I do this? Edit: I got it to work. Just didn't save it after I changed the collision type.
-
This is my code: DeathTrigger.lua (attached to a box) Script.respawnPoint = "" --Entity "respawn point" function Script:Collision(entity, position, normal, speed) if(entity:GetKeyValue("name") == "Player") then spawnPos = self.respawnPoint:GetPosition() --entity:SetPosition(spawnPos) entity:Respawn(spawnPos) end end and FPSPlayer.lua (attached to the player) function Script:Respawn(spawnPos) self.entity:SetPosition(spawnPos) end When they collision I get this error: I have a Pivot indicating the respawn point: Line 65 is this from DeathTrigger.lua: entity:Respawn(spawnPos) From my point of view it should work. Any help? Edit: I just found it out. Turns out that this works: entity.script:Respawn(spawnPos) A little explanation would be welcome
-
If you now, fast objekts skip collision check and move through other objekts. Have engine any standart methods preventing it?
-
Hi. How to check collision whith trigger and other objects and return this objects adress? In C++
-
- C++
- Programming
-
(and 2 more)
Tagged with:
-
Hi, I'm a total beginner in Leadwerks so my question will probably be an easy one I create a new scene. I put a big box (BOX1) in it for the floor, a little box (BOX2) with a mass of 1.0 and a barrel (from "models") with a mass of 1.0. BOX2 and barrel are put above BOX1. When I "run" the scene, BOX2 goes down and collide with BOX1 and stays on it but the barrel goes down and continue to go down through BOX1 and dissapear. I don't understand why the collision is not detected for barrel because all parameters seems identical between BOX2 and barrel. I tried different collision type (prop, scene, debris...) and result is the same in all cases. What did I miss for barrel? Is it because it is not a simple shape as a box or sphere and so the collision must be managed differently (with a script for instance)? Thanks for your help!
-
So, I want the player to enter a collision trigger and that trigger makes it shows a picture, kind of like this script for text but instead of text, it shows a picture. How can I do this? Script.ObjectDescription = "" --String "Object Description" Script.DisplayTimeMax = 5000 --Int "Display time" Script.Used = "0" Script.DisplayTime = 0 Script.DisplayEnabled = false local font1 = Font:Load("Fonts/True Lies.ttf", 20) function Script:Use(context) self.Used = "1" self.CurrentTime = Time:GetCurrent() self.DisplayTime = Time:GetCurrent() + self.DisplayTimeMax end function Script:PostRender(context) if self.Used == "1" then App.context:SetBlendMode(Blend.Alpha) App.context:SetFont(font1) self.DisplayEnabled = true if self.DisplayEnabled == true then if self.DisplayTime > Time:GetCurrent() then App.context:SetColor(255,255,255) context:DrawText(self.ObjectDescription, 100, 600) else self.DisplayEnabled = false self.Used = "0" end end App.context:SetBlendMode(Blend.Solid) end end
-
I have made a simple collision based melee combat system, it seems to work fine, you can take it if you want. But I also have a question about it. As you can see on the video below, weapon collider moves with a small latency, can I do anything to make it follow weapon model faster? Or is it the best result I can get? (Sorry for the video quality) Here is the main code: The idea is very simple: when player equips sword the sword prefab is being loaded and attached to the hand bone. The sword prefab has a sword model and an extra object with collider (WeaponTrigger). Also there is a blood point in the prefab to create blood particles in it's coordinates, but that doesn't matter. In WeaponTrigger start function this entity is being separated from the sword model and in UpdatePhysics it's being moved to the sword model position. Obviously, when this trigger collides with something we can hurt it and stop attack animation.
-
today i build a house. i have a front wall with a door (hole). i set the collision to polymesh. this works awhile. now it does not work anymore!? arrrgg. i remember i put the ground floor a littlebit down only. before i can walk inside only there where the door is. someone know a trick? today also i change to beta of leadwerks engine.
-
I'm trying to make a trigger that will detect collisions with characters, scene and props, but it seems like trigger response type works only for characters. Collision:SetResponse(10, Collision.Scene, 2) Collision:SetResponse(10, Collision.Prop, 2) Collision:SetResponse(10, Collision.Character, 2) self.entity:SetCollisionType(10) This makes my entity work as trigger for characters, but it collides with props and scene. Using 1 as a third parameter makes it collide with everything, using 0 makes it collide with nothing. Is it a bug or intended? Or am I doing something wrong?
-
So I have been working for a few weeks on making and fixing up this code, and am at an impasse. I have the weapon equipping and swinging, but nothing is happening to the monsters. I have the code broken into 2 parts, 1 for the swinging and equip, and 1 (attached to a collision entity on the weapons blade) that when it collides with an enemy ai it is supposed to remove health from them. The second code I also plan on tweaking to include everyone who touches it (for traps) but have no clue. The code that isn't working is here. import "Scripts/Objects/Player/FPSWeapon.lua" Script.damage=10 function Script:Start() self.enabled=true end function Script:Collision(entity, position, normal, speed) if self.enabled then self.component:CallOutputs("Collision") end end function Script:Fire() local enemy = self:FindScriptedParent(Collision.entity,"Hurt") if enemy.script.health>0 then enemy.script:Hurt(self.damage,self.player) end --Blood emitter e = self.emitter[2]:Instance() e = tolua.cast(e,"Emitter") e:Show() e:SetLoopMode(false,true) e:SetPosition(pickinfo.position+pickinfo.normal*0.1) e:SetVelocity(0,0,0) end I brought in collision code directly into it so it would know what it was looking for, and imported the script for fps weapon to get the damage system working. It is showing no errors but at the same time doesn't do anything. Any Ideas? I just want to get it working, so I can tweak it for each weapon and trap.