Jump to content

What am I doing wrong?


Yue
 Share

Go to solution Solved by Yue,

Recommended Posts

My car still can't climb slopes.  Any suggestions?

I have the following script assigned to each tire of the vehicle, I think from my logic it should work. But it doesn't work.

 

-- Script Spring.

Script.chassis = nil --entity "Chassis"
Script.llanta  = nil --entity "Llanta"



--Spring	
local suspension
-- motor
local motor


local vel = 0 
function Script:Start()
	
	--[[
	--Slider. 
	suspension = Joint:Slider(self.entity:GetPosition().x, self.entity:GetPosition().y, self.entity:GetPosition().z, 0, 1, 0, self.chassis, self.entity )  
	--suspension:EnableLimits()
	--suspension:SetLimits(-0.01,-0.05 )
	suspension:SetSpring(200)
	suspension:EnableMotor()
	suspension:SetTargetAngle(0)
	suspension:SetMotorSpeed(1)
    suspension:SetStrength(100)
	
	]]
	--Hinge. 
	motor = Joint:Hinge( self.llanta:GetPosition().x, self.llanta:GetPosition().y, self.llanta:GetPosition().z, 0, 0, 1, self.llanta, self.chassis ) 
	motor:DisableLimits()
	
	--self.llanta:SetFriction(10, 10 ) 
	motor:SetTargetAngle(0)
end



function Script:UpdateWorld()

 
	
   
	
	if window:KeyDown(Key.Up) then 
	
	motor:SetAngle( motor:GetAngle() + 100 )
		motor:EnableMotor()
	vel = vel + 10
	end 
	

	if window:KeyDown(Key.Space) then 
	motor:DisableMotor()
	vel = 0
	end
	
	
	if window:KeyDown(Key.Down) then 
	
	motor:SetAngle( motor:GetAngle() - 100 )
		motor:EnableMotor()
	vel = vel -10
	end
	

	motor:SetMotorSpeed( vel ) 
	
	
		

	
end

 

 

 

Link to comment
Share on other sites

I have discovered something, the previous script is assigned to all the tires, I would expect it to work correctly, for example when I put self.pull:Hide(), the four wheels disappear, this seems to be fine, because the script is assigned to four elements that are the tires, however if I put

if window:KeyDown(Key.Up) then 
    
    engine:SetAngle( engine:GetAngle() - 100 )
        if vel <= 200 then
            vel = vel + 10
        end 
    end 
    
Only one tire gets the strength to move the vehicle, any suggestions please?

Translated with www.DeepL.com/Translator

 

 

Link to comment
Share on other sites

  • Solution

When you know nothing and have to learn by brute force, trial and error, I don't like to copy other people's things, I like to try to understand things, and in a certain way when I can't learn something to decline and stop insisting. But this struggle, even though it goes on alone, today I have learned something new. 

Only one wheel moved because it had to declare the variable as Self.Wheel = Joint:Hinge.   In this case all the tires move with the same script and climb the slope without problems.  

Translated with www.DeepL.com/Translator

 

 

 

 

Link to comment
Share on other sites

"When you know nothing and have to learn by brute force, trial and error, I don't like to copy other people's things, I like to try to understand things"

That's right but we (humans being) all learn(ed) from each other, so I studied here a lot what other people publicated to understand and then try my own. And I'm so happy  people shared things I would never have thought alone...

You can try alone from 0 but it will take loooooong time to understand.

Study the script that have been shared so you would see for example that each wheel needs a joint... And there is much more interesting things you CAN copy (well if you want) and then try to make it better/own things ?

PS I think Josh said SetSpring() works without MotorEnabled() ?

  • Like 1

 

 

Link to comment
Share on other sites

I'm telling you that nothing is perfect, I've made some progress but I'm a long way from being a game, it's just a riddle to solve. 

The new problem is a mistake that happens when the vehicle falls from the top, the suspensions behave incorrectly. I welcome any suggestions. 



 

Script Wheel.lua

 

Script.rueda = nil --entity "Rueda"
Script.chassis = nil --entity "Chassis"




function Script:Start()
	
	
    self.posAmortiguador = self.entity:GetPosition()
	
	
	self.Amortiguador    = Joint:Slider(self.posAmortiguador.x, self.posAmortiguador.y, self.posAmortiguador.z, 0,1,0, self.entity, self.chassis)
	self.Amortiguador:SetSpring(200 )
	
	self.Amortiguador:EnableLimits()
	
	self.Amortiguador:SetLimits( 0, 0.01) 
	self.Amortiguador:EnableMotor()
	
	
	self.posMotor        = self.rueda:GetPosition()
	self.Motor           =  Joint:Hinge( self.posMotor.x, self.posMotor.y, self.posMotor.z, 0, 0, 1, self.rueda, self.entity ) 
	self.Motor:DisableLimits()
	
	self.rueda:SetPickMode( 0 )
	self.entity:SetPickMode( 0 ) 
	
	self.rueda:SetFriction(5, 5 ) 
	
end


local vel = 0
function Script:UpdateWorld()
	
	self.Motor:DisableMotor()
	if window:KeyDown(Key.W) then 
	
	  self.Motor:EnableMotor()
	  self.Motor:SetAngle( self.Motor:GetAngle() - 100 ) 
	
	  
		if vel <=500 then 
			vel = vel + 10 
	
		end 
	

	
	
	
	
	end 
	
	
	
  if window:KeyDown(Key.S) then 
	
	  self.Motor:EnableMotor()
	  self.Motor:SetAngle( self.Motor:GetAngle() + 100 ) 
	
	  
		if vel <=500 then 
			vel = vel + 10 
	
		end 
	

	
	
	
	
	end 


	self.Motor:SetMotorSpeed( vel ) 

	
end

 

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