Jump to content

Making things hover


Core
 Share

Recommended Posts

Ok, I may be out of my depth, but I'm planning a scipt to make an entity to hover over another entity (floor, ramp etc.) I'm just asking am I even near the right path, if I think it would work something like this:

I need to check what is under the entity and get it's shape, surface. PickInfo? Then I need to GetDistance to that entitys nearest point on it's surface. And then if it is too close, I AddForce to thrust up.

Problem is the first part, I'm not sure how to get entitys shape and determine nearest point (the point right under the hovering entity). I'm not asking full script, just some tips and maybe an example how to determine distance between entity and a certain point on another, much larger entitys surface?

Link to comment
Share on other sites

I would start of simple. The few usecase where you would still intersect because of an odd shape can be finetuned later.

  1. Have your floating object send a pick downwards (later this can be multiple picks and various spots of your floating entity).
  2. The pickedposition and your floatobject position has a distance, when this distance is shorter than x, start adding upwards force. Adding the force must be done in the physics update function.
  3. To indicate that you are applying force, place a downward emitting emitter. Everytime you add force, enable the emitter, and distable it again after you have had an update where the distance was large enough.
  4. I also predict some twitchyness of the floating object. It probably will start tilting over, so adding stabilizing side forces is needed. 

Tip: reducing gravity might help you better debug the situation.

Link to comment
Share on other sites

Thanks for the quick responses.

@AggrorJorn, that is exactly what I'm trying to do, though I explained it very badly. I even have emitters allready running and condition for checking distance to the floor. But my problem is Pick, I'm not sure how to actually use it...

@Rick yes, not sure about physics. it just first came to my mind when started to think about this this and thought it might look cool. But I'm very inexperienced with this stuff, so not sure what other alternatives there are. Other than putting no weight on it or placing it on top of an invisible box, like it actually is now :D Well, it almost looks like it is hovering, emitters and all :)

Link to comment
Share on other sites

I'm trying to create small hovering craft type thingy, that follows player. It already follows using Follow() function. Now I'm just trying to make it "see" the ground under it, "see" how far/close it is so it knows when to fire "thrusters" to stay airborne.

Link to comment
Share on other sites

Something like Guilty Spark from Halo? Because you wouldn't need the level of physics details then.

 

Go the API reference and look for World->Pick. The hover entity is the first position and the second position is your (hover entity position - 2 in the y direction). If nothing is returned during that pick, you are not close to the ground and you can start moving it towards to the ground.

Link to comment
Share on other sites

Hmmm... I've only played Halo1. I don't remember Guilty Spark :) But most likely something similar.

But, is this correct, this way I can check if entity hovers over ANYTHING?

local pickInfo = PickInfo()
self.entity.world:Pick(Vec3(0,0,0),Vec3(0,1,0),pickInfo,0,true)

 

But How can I use GetDistance() between picked spot and hovering entity?

 

Edit. Well, about physics, no, I might not need real physics with this one, but I just want it to look like it is hovering above the floor. And it kinda does it now being on top of invisible cube. Well, can I use Springs, or vehicle stuff... Hmmm... That is an area that I have yet not explored at all.

edit2. Oh, just noticed that you wrote more than just about Guilty Spark. I read about Pick already. And thanks! I think I have enough information now to try, ofcourse, I need just the distance when pick happens!

 

Link to comment
Share on other sites

Thanks a ton! We will see if I need to use DistanceTo afterall, this followinf script works and is a good start atleast:

 

self.position = self.entity:GetPosition()
local pickInfo = PickInfo()
if (self.entity.world:Pick(Vec3(self.position.x,self.position.y,self.position.z),Vec3(self.position.x,self.position.y-1,self.position.z),pickInfo,0,true)) == true then
    self.entity:AddForce(0,30,0,true)
end

 

Edit. Oh, and by the way, your Project Saturn video tutorials were fantastic! I learned so much watching them!

Link to comment
Share on other sites

It is good to see that you are making progress. You can shorten this line

if (self.entity.world:Pick(Vec3(self.position.x,self.position.y,self.position.z),Vec3(self.position.x,self.position.y-1,self.position.z),pickInfo,0,true)) 

to

if (self.entity.world:Pick(self.position, Vec3(self.position.x,self.position.y-1,self.position.z),pickInfo,0,true)) 

 

 

9 hours ago, Core said:

Edit. Oh, and by the way, your Project Saturn video tutorials were fantastic! I learned so much watching them!

Glad they helped.

Link to comment
Share on other sites

On 6/14/2017 at 9:57 AM, AggrorJorn said:

It is good to see that you are making progress. You can shorten this line


if (self.entity.world:Pick(Vec3(self.position.x,self.position.y,self.position.z),Vec3(self.position.x,self.position.y-1,self.position.z),pickInfo,0,true)) 

to


if (self.entity.world:Pick(self.position, Vec3(self.position.x,self.position.y-1,self.position.z),pickInfo,0,true)) 

 

Thanks, did that.

 

On 6/20/2017 at 6:29 AM, Josh said:

If you do want to use physics, there's now a kinematic joint that lets you easily control and object's motion.  It's in the docs.

Thanks, going to check them out.

 

But currently I'm actually quite happy, the following script does almost exactly what I hoped! It works and hovering looks cool. I need to add some wall proximity checks etc, but basically it is complete... But is there something I should know about writting a good code? This is actually my first script I started from scratch, before I have only customized allready working scripts to suit my needs.

Still very new with this stuff, so I would appreciate if bad habits or other bad stuff in this script would be pointed out! Especially the part in the code with Entitys rotation. I use Point function, but also SetInput, where I need to set angle also. So basically I set entitys angle (rotation) twice, but it was the only way to get this working like I wanted.

--Setup variables
Script.enabled = true--bool "Enabled"
Script.target = nil--entity "Target"
Script.accurateFollowRange = 6
Script.stopRange = 3
Script.targetDistance = nil
Script.position = nil
Script.maxaccel=0.5
Script.speed = 0 
Script.realSpeed = nil
Script.rotSpeed = 0.05
Script.angle = nil
Script.text5 = "CART" --string "Content Msg."
Script.started = false

--Thruster Control --
Script.altitudeLow = nil
Script.altitudeHigh = nil
Script.altitudeOptimal = nil
Script.thrustForce = Vec3(0,0,0)
Script.coldStart = true
--Thruster Control --

--Message Timer-- not in use atm
Script.messagetimecount = 0
Script.messagetime = 1000 --int "Message Time"

	
function Script:Start()
self.speed = 0
self.entity:FindChild("Jet1"):Hide()
self.entity:FindChild("Jet2"):Hide()
self.entity:FindChild("Radiator1"):Hide()
self.entity:FindChild("Radiator2"):Hide()
self.entity:FindChild("HeadLight"):Hide()
self.entity:FindChild("Heathaze1"):Hide()
self.entity:FindChild("Heathaze2"):Hide()

end


function Script:UpdatePhysics()

	--Update entity data
	self.realSpeed = self.entity:GetVelocity(true)
	self.targetDistance = self.entity:GetDistance(self.target)
	self.position = self.entity:GetPosition()
	self.angle = self.entity:GetRotation()

	--Ground proximity picks
	local pickInfo = PickInfo()
	self.altitudeLow = self.entity.world:Pick(self.position, Vec3(self.position.x,self.position.y-0.5,self.position.z),pickInfo)
	self.altitudeHigh = self.entity.world:Pick(self.position, Vec3(self.position.x,self.position.y-0.55,self.position.z),pickInfo)
	self.altitudeOptimal = self.entity.world:Pick(self.position, Vec3(self.position.x,self.position.y-0.6,self.position.z),pickInfo)
	
	--Main movement and hover control
	if self.started == true then
		self.entity:Stop()
		self.entity:AddForce(self.thrustForce)
		self.entity:SetInput(self.angle.y,self.speed,0,0,false, 0.5, 0.5, true, self.rotSpeed)
		
		--Follow close, more accurate
		if self.targetDistance > self.stopRange and self.targetDistance < self.accurateFollowRange then
			self.entity:Stop()
			self.speed = 1
			self.entity:Point(self.target, 2, Time:GetSpeed() * self.rotSpeed)	
		end	

		--Follow far
		if self.targetDistance > self.accurateFollowRange then
			self.entity:Follow(self.target,self.speed,self.maxaccel)
		end
		
		--Stop when near player
		if self.targetDistance < self.stopRange then
			self.entity:Stop()
			self.speed = 0
		end

		-- Altitude control
		if self.altitudeLow == true and self.coldStart == false and self.realSpeed.y < 0.3 then
			self.thrustForce.y = 0.43
		else
			self.thrustForce.y = 0.42
		end

		if self.altitudeHigh == false then
			self.thrustForce.y = 0.41
			self.coldStart = false
		else
			self.thrustForce.y = self.thrustForce.y + 0
		end
	end
end


--Start/Stop
function Script:Use(player)
	if self.started == true then
		self.started = false
		self.thrustForce.y = 0
		self.speed = 0
		self.entity:FindChild("Jet1"):Hide()
		self.entity:FindChild("Jet2"):Hide()
		self.entity:FindChild("Radiator1"):Hide()
		self.entity:FindChild("Radiator2"):Hide()
		self.entity:FindChild("HeadLight"):Hide()
		self.entity:FindChild("Heathaze1"):Hide()
		self.entity:FindChild("Heathaze2"):Hide()
	else
		self.started = true
		self.coldStart = true
		self.entity:FindChild("Jet1"):Show()
		self.entity:FindChild("Jet2"):Show()
		self.entity:FindChild("Radiator1"):Show()
		self.entity:FindChild("Radiator2"):Show()
		self.entity:FindChild("HeadLight"):Show()
		self.entity:FindChild("Heathaze1"):Show()
		self.entity:FindChild("Heathaze2"):Show()
	end
end

Now, I'm off to continue to learn csg and level design, fun stuff! Might pick up one of those scifi texture packs... Allready bought Scifi Interior Construction Kit.

And here is a shot of the "CART" inventory carrier. This is a great mile stone in my game making "career", I have built a small test scene with csg, learned the basics of 3d modeling and imported my own, self painted and textured model inside a game engine and scripted it to work! Nothing can stop me now :)

 

20170623022420_1.jpg

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...