-
Posts
5 -
Joined
-
Last visited
Content Type
Blogs
Forums
Store
Gallery
Videos
Posts posted by SpiritMacardi
-
-
Trying to set the velocity never worked for me with the character controller, hence why I used AddForce. This does work for jumping too though; I made sure that this script wouldn't interfere with the Y axis, only adjust the Z and X.
As for the full script and examples, I'll hopefully have something to show off soon.
-
So when I started working with Leadwerks, my goal was to make a 2.5D platformer. I'd been making some great progress in that regard, mainly by using Pivots to create a movement path (pressing a direction makes the player turn and move toward one of two pivots, and once a pivot is reached the next/previous set of pivots in the sequence are swapped in).
Now one issue had become a big problem, and it's one which I've seen others here struggle with as well: being pushed off-path by objects in the player's path. This problem nearly made me scrap my progress and switch to a different engine... But I found out how to fix it!
This method doesn't exactly "lock" the movement axis, but rather applies a sort of rubberband effect when the player gets too far off-course. The code isn't as streamlined as it could be, since I only just made it, but it works and I want to share it with others who may have been dealing with the same problem.
If you have any questions, feel free to ask!
distanceRight = self.entity:GetDistance(self.rightPath) distanceLeft = self.entity:GetDistance(self.leftPath) local correctionP = Vec3(self.entity:GetPosition(true).x - self.leftPath:GetPosition(true).x, 0, self.entity:GetPosition(true).z - self.leftPath:GetPosition(true).z) local correctionW = Vec3(self.rightPath:GetPosition(true).x - self.leftPath:GetPosition(true).x, 0, self.rightPath:GetPosition(true).z - self.leftPath:GetPosition(true).z) correctionP = correctionP / correctionP:DistanceToPoint(Vec3(0, 0, 0)) correctionW = correctionW / correctionW:DistanceToPoint(Vec3(0, 0, 0)) correctionP:Normalize() correctionW:Normalize() local correctionD = (correctionP * distanceLeft) if correctionD:DistanceToPoint(correctionW * distanceLeft) > 0.1 then local correction = Vec3((correctionW.x * distanceLeft) - correctionD.x, 0, (correctionW.z * distanceLeft) - correctionD.z) correction = correction * self.moveSpeed self.entity:AddForce(correction, true) end
-
I hadn't gotten any errors, and I just tried your suggestion and I'm still not getting any results.
Scratch that! I just got a working raycast by simply setting the GetPosition() commands to true!
-
First of all, hey everyone! I'm new to the forums, and I've been using/learning Leadwerks since the beginning of this year. It's been my first ever experience with making games, and I love how easy to use the engine is.
Anyway, I've hit a bit of a snag in my current endeavors. Basically, I'm trying to have it so that the character of my game attacks using a sphere that appears, moves forward a set amount, and then returns and vanishes once more. To detect a hit, I figured it would make sense to have a raycast that projects from the start point of the sphere out to its current position, but it fails to detect anything. I'll leave a copy of my code below, and hopefully someone will be able to tell me what I'm doing wrong and how I can correct it.
Script.player = "" --entity "Player" Script.ringStart = "" --entity "Start position" Script.ringEnd = "" --entity "End position" function Script:Start() self.returning = false self.entity:Hide() end function Script:UpdatePhysics() local pickinfo = PickInfo() if self.entity:Hidden() == false then if self.returning == false then if self.entity:GetDistance(self.ringEnd) < 0.1 then self.returning = true else self.entity:Move(0.1, 0, 0) local bulletPos = self.entity:GetPosition(false) local startPos = self.ringStart:GetPosition(false) if (self.entity.world:Pick(bulletPos, startPos, pickinfo, 0, false)) then System:Print("Part 1 working") end end end if self.returning == true then if self.entity:GetDistance(self.ringStart) < 0.1 then self.returning = false self.entity:Hide() else self.entity:Move(-0.1, 0, 0) end end end end
Working 2.5D
in Programming
Posted
Yeah, I've done this using the character physics and SetInput function. You could probably alter this for rigid body physics, but I haven't tried myself.
Just be sure to have this code execute after the SetInput function. Otherwise you can end up with the character being catapulted across the screen.