About Store Forum Documentation Contact



Post Reply 
Problem with friction
Author Message
Outdoordoor Offline
Member

Post: #1
Problem with friction
I'm trying to make a character controller, but for some reason the actor always gets stuck on the terrain like the friction is very high. I tried disabling all the friction on the character actor, disabling gravity, but the problem is the same. When the actor is in the air, it controls as expected, but the moment it touches ground, it completely stops, except for tiny motion when moving downhill.

How to fix this problem?

For the controller I'm using the code from the tutorial:
Code:
Physics.startSimulation().stopSimulation();

  
   Flt s=3;
   Vec vel(0, 0, 0);
   if(Kb.b(KB_W))vel+=!PointOnPlane(Cam.matrix.z, Vec(0, 1, 0))*s;
   if(Kb.b(KB_S))vel-=!PointOnPlane(Cam.matrix.z, Vec(0, 1, 0))*s;
   if(Kb.b(KB_A))vel-=!PointOnPlane(Cam.matrix.x, Vec(0, 1, 0))*s;
   if(Kb.b(KB_D))vel+=!PointOnPlane(Cam.matrix.x, Vec(0, 1, 0))*s;
   ctrl.update(vel, Kb.shift(), Kb.bp(KB_SPACE) ? 3.5 : 0);
(This post was last modified: 10-18-2023 07:48 AM by Outdoordoor.)
10-17-2023 08:38 PM
Find all posts by this user Quote this message in a reply
Outdoordoor Offline
Member

Post: #2
RE: Problem with friction
To fix the problem I made a workaround which uses a separate helper controller. Here's the code if someone needs it:

Code:
helperCtrl.createCapsule(0.4, 1, ctrl.center());

Code:
double camYaw = ActiveCam.yaw;
  
   Vec vel(0, 0, 0);
   if(Kb.b(KB_W))vel+=Vec(Sin(-camYaw), 0, Cos(-camYaw)) * speed * 50 * Time.d();
   if(Kb.b(KB_S))vel-=Vec(Sin(-camYaw), 0, Cos(-camYaw)) * speed * 50 * Time.d();
   if(Kb.b(KB_A))vel-=Vec(Cos(camYaw), 0, Sin(camYaw)) * speed * 50 * Time.d();
   if(Kb.b(KB_D))vel+=Vec(Cos(camYaw), 0, Sin(camYaw)) * speed * 50 * Time.d();
  
   helperCtrl.actor.ignore(ctrl.actor, true);
   helperCtrl.update(vel, Kb.ctrl(), Kb.bp(KB_SPACE) ? 3.5 : 0);
   ctrl.actor.pos(helperCtrl.center()-Vec(0, helperCtrl.radius(), 0));
10-18-2023 12:08 PM
Find all posts by this user Quote this message in a reply
Post Reply