Jump to content

set position of controller


Rick
 Share

Recommended Posts

This is kind of hard to explain but I'll try my best. I have a few thingoids that act on each other. I have a character thingoid. This has a character model, controller, and the editor model. I also have a DeathPlaneTrigger thingoid. This creates a plane and when target 0 is below this plane it will send a message to target 1 "activate". In this example the character thingoid editor model is target 0 and target 1 is another thingoid called PositionTrigger. This takes target 0 and places it at target 1. In this example target 0 is the character editor model and target 1 is just a pivot thingoid.

 

OK, so the idea is when my character thingoid is below the death plane it'll trigger the position trigger which will put the character back up on the platform. In this position trigger I check to see if the type property (I made) of the target is of "character". If it is, I get the characters controller and call SetPosition() on the controller to the pivots position which is on top of a platform. This indeed does set the position of the controller to where it should. The issue is it's not setting the character model or the character editor model with the controller's new position. The reason it should do this is because in the character's Update() method when in game mode, the character model and character editor model are setup to follow the controller via it's position, and that works great normally, but not when this Position Trigger moves the controller.

 

So can anyone think of any reason that the controller is getting set correctly but the character model and character editor model aren't following it?

 

 

This is the character thingoid Update() method

function object:Update()
	if GetGlobalString("mode") == "GAME_MODE" then
		if self.characterModel ~= nil then
			self.controller:Update(self.rotation, self.move, self.strafe, self.jump, 5000, 10, 0)
			self.jump = 0		-- reset each frame

			local pos = object.controller:GetPosition(1)

			-- the character model must follow the controller
			-- for the 3rd person camera to work we must also move the object model since that's the target of the camera
			self.model:SetPosition(pos)
			self.characterModel:SetPosition(pos)
			self.characterModel:SetRotation(Vec3(0, object.controller.rotation.y + 180, 0))

			-- the 
			t = model:GetTarget(0)
			if t ~= nil then
				objecttable[t].playerPivot:SetRotation(Vec3(objecttable[t].playerPivot:GetRotation().x, object.rotation+90, objecttable[t].playerPivot:GetRotation().z))
			end
		end
	else
		-- constantly update the controller to the object in the editor
		object.controller:SetPosition(object.model:GetPosition())

		-- make the model follow
		if self.characterModel ~= nil then
			self.characterModel:SetPosition(object.model:GetPosition())
		end
	end
end

 

 

This is the PositionTrigger's RecieveMessage() method

function object:ReceiveMessage(message,extra)
	if message == "activate" then
		t1 = model:GetTarget(0)
		t2 = model:GetTarget(1)

		if t1 ~= nil and t2 ~= nil then
			if objecttable[t1].type ~= nil then
				if objecttable[t1].type == "character" then
					-- special case for characters. we want to move the controller
					objecttable[t1].controller:SetPosition(t2:GetPosition(1), 1)
				else
					-- move the model
					t1:SetPosition(t2:GetPosition(1), 1)
				end
			else
					-- move the model
					t1:SetPosition(t2:GetPosition(1), 1)
			end
		end
	else
		self.super:ReceiveMessage(message,extra)
	end
end

 

And here is the DeathPlaneTrigger Update() method

 

function object:Update()
	if GetGlobalString("mode") == "GAME_MODE" then
		t1 = model:GetTarget(0)
		t2 = model:GetTarget(1)

		if t1 ~= nil and t2 ~= nil then
			if t1:GetPosition(1).y < object.plane:GetPosition(1).y then
				t2:SendMessage("activate", "0", "")
			end
		end
	else
		object.plane:SetPosition(object.model:GetPosition(1))
	end
end

Link to comment
Share on other sites

The strange thing is that in the characters Update() method it sets the position of the character model and the editor model to the controller. I do this instead of parenting. So it's almost as if after setting the position of the controller it still returns it's old position even though it visually is shown at the new position.

 

Maybe that's the issue. Because even when the controller has it position set to the new place I'm able to move the character model around as if the controller is still on it.

 

The reason I think that is, is because I'm checking the editor model Y value to see if it's below this death plane, and because it doesn't follow the controller back up above the dealth plane that criteria of it being below is always met.

Link to comment
Share on other sites

So what's happening is that even though I'm calling SetPosition() on the controller and moving it above the Y value of this death plane, the Y value check against the controller and the death plane is still being met. Somehow after I SetPosition() on the controller above the Y value, it still thinks it's below the Y value.

 

Why would that be? Shouldn't SetPosition() on a controller change it's position?

 

 

So what I did was put a Print() to the log before I move the controller and after I move the controller. Before shows the Y is < the death plane. After shows it's now above the death plane, but it keeps going into this check each cycle. So it's like something is moving it back down each cycle.

Link to comment
Share on other sites

  • 4 weeks later...

I have not, but I would think it to produce the same results. The reason I didn't try that is because I would have to point the controller to where I want it and then call MoveEntity(), but all I want is to position the controller at a specific spot instantly.

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...