Player lightcontrol

How i can lightcontrol to the player?

If you want light to affect your player, then attach your player to a node and attach the light to that.

If you want your player to be a source of light, then add the light to the rootNode, but add it as a control to the player and make it follow the player around

exacly how wezrule said, but if you want affect only your player, as i good remember you can just add light to spatial(geometry or node - not only node).

also you know it is PointLight for rootNode(if you want affect scene where player is), and AmbientLight for player spatial(if you want affect only player).

there is no player.addControl(lightControl);.

if you want to have player “highlighted” you make “player.addLight(al)” where al is AmbientLight

if you want to make control, then make sure it extend JME Control class and then you can do “player.addControl(yourcontrol)”

also “player” need to be Spatial(Spatial = Geometry OR Node)

So i can not be CharacterControl?

using tutorial and ready to use LightControl:

PointLight myLight = new PointLight();
LightControl lightControl = new LightControl(myLight);
spatial.addControl(lightControl); // this spatial controls the position of this light.

where spatial = your player. so player need to be spatial.

is this so hard?

no.I just hoped to be more easy.

Possibly this will help. Have a try to play with it:

Edited: Or you will need RimShader:

aaahhhh… possibly you just want to add light… LightControl… sorry, i misunderstood you.

Why when I turn 180 degrees my light disappears?

[java]package mygame;


import com.jme3.system.AppSettings;

import com.jme3.material.Material;

import com.jme3.bullet.BulletAppState;

import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;

import com.jme3.bullet.collision.shapes.CollisionShape;

import com.jme3.bullet.control.CharacterControl;

import com.jme3.light.SpotLight;

import com.jme3.math.FastMath;

import com.jme3.bullet.control.RigidBodyControl;

import com.jme3.bullet.util.CollisionShapeFactory;

import com.jme3.input.KeyInput;

import com.jme3.input.controls.ActionListener;

import com.jme3.input.controls.KeyTrigger;

import com.jme3.light.AmbientLight;

import com.jme3.light.DirectionalLight;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.scene.Spatial;

public class Main extends SimpleApplication

implements ActionListener {

private Spatial sceneModel;

private BulletAppState bulletAppState;

SpotLight myLight;

private RigidBodyControl landscape;

private CharacterControl player;

private Vector3f walkDirection = new Vector3f();

private boolean left = false, right = false, up = false, down = false;

public static void main(String[] args) {

Main app = new Main();

AppSettings settings=new AppSettings(true);





public void simpleInitApp() {

bulletAppState = new BulletAppState();


viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));




sceneModel = assetManager.loadModel("Models/water.obj");


Material mat1 = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");




CollisionShape sceneShape = CollisionShapeFactory.createMeshShape(sceneModel);

landscape = new RigidBodyControl(sceneShape, 0);


CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);

player = new CharacterControl(capsuleShape, 0.05f);




player.setPhysicsLocation(new Vector3f(0, 10, 0));






private void flash()


myLight = new SpotLight ();


myLight.setSpotInnerAngle(15f * FastMath.DEG_TO_RAD);

myLight.setSpotOuterAngle(35f * FastMath.DEG_TO_RAD);




private void setUpLight() {

AmbientLight al = new AmbientLight();



DirectionalLight dl = new DirectionalLight();


dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());


private void setUpKeys() {

inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_A));

inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_D));

inputManager.addMapping("Up", new KeyTrigger(KeyInput.KEY_W));

inputManager.addMapping("Down", new KeyTrigger(KeyInput.KEY_S));

inputManager.addMapping("Jump", new KeyTrigger(KeyInput.KEY_SPACE));

inputManager.addListener(this, "Left");

inputManager.addListener(this, "Right");

inputManager.addListener(this, "Up");

inputManager.addListener(this, "Down");

inputManager.addListener(this, "Jump");


public void onAction(String binding, boolean value, float tpf) {

if (binding.equals("Left")) {

left = value;

} else if (binding.equals("Right")) {

right = value;

} else if (binding.equals("Up")) {

up = value;

} else if (binding.equals("Down")) {

down = value;

} else if (binding.equals("Jump")) {





public void simpleUpdate(float tpf) {

Vector3f camDir = cam.getDirection().clone().multLocal(0.3f);

Vector3f camLeft = cam.getLeft().clone().multLocal(0.3f);

walkDirection.set(0, 0, 0);

if (left) { walkDirection.addLocal(camLeft); }

if (right) { walkDirection.addLocal(camLeft.negate()); }

if (up) { walkDirection.addLocal(camDir); }

if (down) { walkDirection.addLocal(camDir.negate()); }







Really nobody know why is that?

You don’t really explain what or why you are trying to do or what happens.

Most likely you are moving away from the spot or looking towards it and seeing the back of things but really there is no way to know.

Ok when i start i see my flashlight i see the light very clear ,but when i turn to left

the light or right the light brightness get lower and lower until it become 0 at 90 degress from my starting position. When i get back in the start position everything is ok.

The light dont whant to go above 1f.

Does the light actually move at all when you turn or just stay where it is?

Well. I have made a second light source and i tried to turn it to 180 degrees but i stuck to 90.Whit my “flashlight” I can trun to 180.

Here is the video of the problem

  • You have some issues with vector math.
  • Try to create a CameraNode and attach there your camera and your light source.

Like this ?